ensuring unique field value in MySQL using PHP
| From: | Janet Valade | Date: | Tue, 29 Jan 2002 03:24:21 +0000 |
| Subject: | ensuring unique field value in MySQL using PHP | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16267@lists.php.net to get a copy of this message | ||
I have a form in which users create their own login name. The code for
storing the login name they created does something like the following:
$userlogin is the name the user typed in the form
$sql = "select loginname from login where loginname='$userlogin'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if ($num > 0)
{
echo "Sorry, that login name is already taken, Try another";
shows form again;
}
else
insert new record into database;
echo "okay, your new account is added";
I am wondering if it is possible that two people could hit the submit button
at the exact same time with the same login name so that the same login name
could get entered twice? Seems unlikely that this would happen by accident,
but is this something a hacker could do on purpose?
Thanks,
Janet