I'm writing a survey, trying to enter data from a form into my database. I want to set it up so people can only enter the survey once and when they submit it i'll email a thank you. My code isnt' working, I can enter data into the database, but I added a conditional to check for if the email exists and if so, tell user bye:
// conect to my mysql database
$con = mysql_connect("sql02.mysite.com", "myuser", "mypass")or die("Connect Error: ".mysql_error());
$db = ("grp");
mysql_select_db($db, $con) or die (mysql_error());
//check for previous entry keyed to email
$chkEmail = mysql_query("SELECT * from survey where Email = '.$Email.'", $con) or die ("cannot get Database open");
if ($chkEmail)
{
printf ("<center><h2>You have already done this survey");
printf ("<center><h2>thanks!");
exit;
}
// insert data into the database grp
$myquery = "INSERT INTO survey (Email, Q1, Q2) VALUES
('".$Email."', '".$Q1."','".$Q2."')";
$result = mysql_query($myquery);
if ($result)
{
//Once the data is entered, redirect the user to give them visual confirmation
header("location: thanks.php");
exit;
}