RE: ensuring unique field value in MySQL using PHP

From: Date: Tue, 29 Jan 2002 03:49:15 +0000
Subject: RE: ensuring unique field value in MySQL using PHP
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-16268@lists.php.net to get a copy of this message
Checking a small database for username/password combination would happen so quick, it would be nearly impossible for two usernames to be entered in. Your script should work properly, but to make sure no duplicates are entered, you can change the column definition using the "ALTER columnName" command to make sure there are no duplicates. Look in the mySQL documentation (www.mysql.com) to find the correct command. Adam -----Original Message----- From: Janet Valade [mailto:jvalade1@san.rr.com] Sent: Tuesday, January 29, 2002 1:24 PM To: php-db@lists.php.net Subject: ensuring unique field value in MySQL using PHP 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

« previous php.db (#16268) next »