I found this, Form submission will not stop for validation, but it is based of of JQUERY and not PHP. Should I not use PHP and switch?
So I have what I think to be a validated form. Problem is that if the form information is not right, my site will go ahead and forward the registrar to the next page. I will leave my form code below, and maybe you guys who are better at this than me, will have the kindness and compassion to help me as usual. After that I will show you how I am processing the information. Thanks for all you guys do. I am just very confused. Thanks again and happy 2014.
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["first_name"]))
{$first_nameErr = "Required";}
else
{
$first_name = test_input($_POST["first_name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$first_name))
{
$first_nameErr = "Only letters allowed";
}
}
if (empty($_POST["last_name"]))
{$last_nameErr = "Required";}
else
{
$last_name = test_input($_POST["last_name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$last_name))
{
$last_nameErr = "Only letters allowed";
}
}
if (empty($_POST["email"]))
{$emailErr = "Required";}
else
{
$email = test_input($_POST["email"]);
// check if e-mail address syntax is valid
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]...
{
$emailErr = "Invalid email format";
}
}
if (empty($_POST["password"]))
{$passwordErr = "Required";}
else
{$password = test_input($_POST["password"]);}
if (empty($_POST["gender"]))
{$genderErr = "";}
else
{$gender = test_input($_POST["gender"]);}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div class="signupitsfree" float="right">
<p class="signup">Sign Up
It's Completely Free!</p>
<form method="POST" name="signup" action="life/chickenwings.php">
<label for="first name"></label><input id="first name" name="first_name"
placeholder="First Name" type="text" value="<?php echo $first_name;?>" /> <span
class="error">* <?php echo $first_nameErr;?></span>
<label for="last_name"></label><input id="last name" name="last_name"
placeholder="Last Name" type="text" value="<?php echo $last_name;?>" />
<span class="error">* <?php echo $last_nameErr;?></span>
<br><br>
<label for="email"></label><input id="email" name="email" placeholder="Email"
type="text" value="<?php echo $email;?>" />
<span class="error">* <?php echo $emailErr;?></span>
<label for="password"></label><input id="password" name="password" placeholder="Create
Password" type="password" />
<span class="error">* <?php echo $passwordErr;?></span>
<label for="male"><strong>Male</strong></label> <input id="male" value="male" <?php if
(isset($gender) && $gender=="male") echo "checked";?> name="gender" type="radio" />
<label for="female"><strong>Female</strong></la... <input id="female" value="female"
<?php if (isset($gender) && $gender=="female") echo "checked";?> name="gender"
type="radio" />
<span class="error">* <?php echo $genderErr;?></span>
<label for="submit">"I Agree To <a href="#">Terms And Conditions"</a></label> <input
id="submit" value="Submit" type="submit" name="submit"/>
<p><span class="error">* required field.</span></p>
<hr>
Now is the way I am processing the information.
<?php
$hostname="figureitout";
$username="figureitout";
$password="figureitout";
$dbname="figureitout";
$db_conx = mysqli_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
if(mysqli_connect_errno()){
echo mysqli_connect_error();
exit();
}
$select = mysqli_select_db($db_conx,$dbname);
$first_name= $_POST["first_name"];
$last_name= $_POST["last_name"];
$email= $_POST["email"];
$password= $_POST["password"];
$gender= $_POST["gender"];
mysqli_query($db_conx,"INSERT INTO users (firstname, lastname, email, password,
gender)
VALUES ('$first_name', '$last_name', '$email', '$password', '$gender')");
mysqli_close($db_conx);
header("Location: chicken/wing.php")
?>