I have a file which processes the data submitted by the form. I want to check whether the data submitted is identical to the data in mysql database so that if it is not the user corrects the form and submits it again. Here is the code which cannot check the data in submitted form:
<?php
global $HTTP_POST_VARS;
if (isset($HTTP_POST_VARS['mybutton'])) {
$Host = "";
$DBName = "";
$TableName = "patientsform";
$Link = mysql_connect ($Host, '', '');
if ($Link==false) {
echo mysql_errno().": ".mysql_error()."<BR>\n";
}
mysql_select_db ($DBName, $Link);
$Query1 = "SELECT Forename FROM patients WHERE Forename = {$HTTP_POST_VARS['forename']} AND Surname = {$HTTP_POST_VARS['surname']}";
//The query to check the data submitted
$Query = "INSERT INTO $TableName VALUES ('0', '{$HTTP_POST_VARS['forename']}')";
//The query to put the submitted data into the table
if (mysql_query ($Query1, $Link)) {
print "The query1 was successfully executed!<BR>\n";
if (mysql_query ($Query, $Link)) {
print "The query was successfully executed!<BR>\n";
}
else {
print "The query could not be executed!<BR>\n";
echo mysql_errno().": ".mysql_error()."<BR>\n";
}
}
else {
print "The query1 could not be executed!<BR>\n";
echo mysql_errno().": ".mysql_error()."<BR>\n";
}
mysql_close($Link);
} //end of isset function
else {
echo "you must have come here from somewhere else.\n";
}