Check against database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Check against database

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
}
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Thanks :)
Post Reply