Hi! Thanks for taking the time to read this!
I'm building a site to collect data for a researcher—-my first php/mysql site...
I have a basic script that is malfunctioning. The researcher wants a person who has signed in to not be able to sign in again (one of multiple ways to make sure the survey is not taken twice by the same person). I’ve broken the code down and tested it in sections to find the problem, but can’t find a solution to it anywhere I’ve looked.
In the simplified script, if I type in a name in the web interface (html form) that is already in the database, my script tells me that the name I’ve typed in is not already in the database. Here’s the simplified code:
/set variables for database access/
$Host = "localhost";
$User = "";
$Password = "";
$DBName = "";
$TableName = "";
$Link = mysql_connect($Host, $User, $Password);
$Query = "SELECT last_name FROM identities WHERE email_address = '$email_address'";
/this part retrieves the data from the database/
$last_name2 = mysql_db_query ($DBName, $Query, $Link);
/this part disconnects from the database/
mysql_close ($Link);
/check to see if it happened/
IF(!$last_name2){
print("… an html error message…
");
exit();
}
/tell me about the result of the data comparison/
IF ($last_name != $last_name2) {
echo ("last names do not match");
exit();
} ELSE{
echo ("last names do match");
}
More specifically, I get the "last names do not match" message printed even though the name I’ve entered matches exactly the name that is associated with the incoming email address as the "select and echo" script to show the databases’ contents shows.
If anyone could tell me why on earth I get the opposite of what I want, I would be extremely grateful.
Thanks,
James Baker