faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 7 people (57%) answered Yes
Recently 2 of 3 people (67%) answered Yes

Entry

How do I get PHP to check a MySQL dbase for a password and username to ensure that users cannot choose identical names and passwords

May 2nd, 2007 06:21
lorenzo campanis, Nick Oakley, Ben Udall,


You need to query for a username with
$res = mysql_query("select username from users
                           where username =
'".addslashes($_POST['username']). "'");
if(mysql_num_rows($res) > 0)
{
...you have a user
}
$_POST['username'] is the variable passed by your input box in your form.
addslashes will make sure you dont get an error in MySQL when O'Brien is
the username. visit php.net for more