Not inserting


I have created a database, and once the form is submitted, it’s not inserting into the database. Can anyone see an error in this code?


$submit = $_POST['submit'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$birthdate = $_POST['birthdate'];
$email = $_POST['email'];
$phone = $_POST['phone'];

if (!$submit) {
$message= "<center><b>Register now and save $2 at the door!<i><br />
 * = required field</;></i></center>";

if ($submit && (!$firstname || !$lastname || !$birthdate)){
$error= "<center><b>You didn't fill in all Required fields. Please try again!</b></center>";

if (($submit && $firstname && $lastname && $email) &&
(!preg_match("/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\\.[a-zA-Z0-9-.]+$)+/", $email))){
$error= "<center><b>Invalid E-Mail Address. Please Try Again!</b></center>";

if (($submit && $firstname && $lastname && $email && $phone) &&
(!preg_match("/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\\.[a-zA-Z0-9-.]+$)+/", $email))){

$con = mysql_connect("localhost","root","");

if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db("crash", $con);
$sql = "INSERT INTO attendees (firstname,lastname,birthdate,email,phone)
VALUES ('$firstname','$lastname','$birthdate','$email','$phone')";

if (!mysql_query($sql, $con))
die('Error: ' . mysql_error());
$message= "<center><b>Thank you.  You are now registered</b></center>";

header ("Location: yay.php");



Are you developing locally?

Yes, I am.

Please check your database name, table names, field names, make sure they are exact.

What error if any is MySQL giving?