it validates and displays the errors in my arrays properly, however it doesn't POST to my database. All the naming of fields is correct on the form (case correct too), PHP, and MYSQL, dbconnect.php are all correct and proper. The problem i believe is somewhere in the array function. Now I just started learning PHP this month so please go easy on me. Thanks for the help!
<?php
include ('scripts/dbconnect.php');
$Name = mysql_real_escape_string($Name);
$Email = mysql_real_escape_string($Email);
if (isset($_POST['formsubmitted'])) {
$error = array();//Declare An Array to store any error message
if (empty($_POST['Name'])) {//if no name has been supplied
$error[] = 'Please Enter Your Name ';//add to array "error"
} else {
$Name = $_POST['Name'];//else assign it a variable
}
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['Email'])) { //regular expression for email validation
$Email = $_POST['Email'];
} else {
$error[] = 'Your EMail Address is Invalid ';
}
}
if (empty($error)) //Send to database if no errors
mysql_query("INSERT INTO InviteRequestDB ( 'Name', 'Email' ) VALUES ( '$Name', '$Email' )");
mysql_close($connect); //Close connection to database
foreach ($error as $key => $values) {
echo "<li style=color:#FFF> $values </li>";
}
?>
Now I know I shouldn't be using mysql. But I ran into too many problems with mysqli and this is just a simple contact form.
Also should I be doing mysql_real_escape_string on each variable as i am doing now? Or is the order of the procedure not correct?
<form action="applyforinvite.php" method="post">
<input class="textbox" type="text" name="Name" />
<input class="textbox" type="text" name="Email" />
<input type="hidden" name="formsubmitted" value="TRUE" />
<input type="submit" value="Register" />
</form>
Thanks for the help!