I am having a problem loading a fresh "thankyou.php" file after a form has been submitted. The form sends data to itself and if all the data passes validation it then proceeds to save them in the database.
The "thankyou.php" quite loads but the "signup.php" still remains and the output of both files remain in the same page. I want it on a fresh page but it won't work.
Here is my sanitation:
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["firstName"]))
{$Err[] = "* First Name is required";}
else
{
$name = test_input($_POST["firstName"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name))
{
$Err[] = "Only letters are allowed in First Name";
}
}
if (empty($_POST["email"]))
{$Err[] = "* Email is required";}
else
{
$email = test_input($_POST["email"]);
// check if e-mail address syntax is valid
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
$Err[] = "Invalid email format";
}
}
}
And the form:
<div id = "signupform">
" >
Email Address
First Name
And database connection and insertion:
try {
$conn = new PDO('mysql:host=localhost; dbname=mydb', 'root', '');
$conn->setAttribute(PDO:: ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $pe) { echo('Connection error, because: ' .$pe->getMessage()); }
//Insert data to Database if values are not empty and sanitized if (!empty($_POST["firstName"]) && !empty($_POST["email"])) { $qry = "INSERT INTO userdetails (email, firstName) values (?, ?)";
$q = $conn->prepare($qry) or die("ERROR: " . implode(":", $conn->errorInfo()));
$q->bindParam(1, $email);
$q->bindParam(2, $firstName);
try {
if($q->execute()){
header("Location: invoice.php");
exit;
}
}
catch(PDOException $pe) {
echo('Connection error, because: ' .$pe->getMessage());
}
}
And that's all but it is still not loading a fresh page.