Page 1 of 1

Check against database

Posted: Sun Jun 12, 2005 2:48 pm
by Parody
This is a php/mysql question but it is more based around php, so I put it in PHP-CODE, sorry if this is the wrong place :oops:

I need to check a username against those in a mysql database, to see if it is the same as any others, and if so, die.

What queries and php do I need to write?

Posted: Sun Jun 12, 2005 3:44 pm
by Chris Corbyn
There's a few ways to do it. One of them being....

Code: Select all

$query = "SELECT COUNT(*) as `tot` FROM `table` WHERE `username`='$username'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_result($result,0,'tot') != 0) {
    //die
}

Posted: Sun Jun 12, 2005 4:13 pm
by Parody
Thanks :)