Re: Checking database for a value
| From: | Miguel Cruz | Date: | Sat, 20 Apr 2002 17:09:11 +0000 |
| Subject: | Re: Checking database for a value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-93825@lists.php.net to get a copy of this message | ||
On Sun, 21 Apr 2002, Denis L. Menezes wrote:
> I am looking into 4 books in front of me but somehow cannot find the
> following :
>
> I have a field userid which the user fills in at registration. Before
> entering the data into the database, I want to check if the userid exists in
> the database.
>
> Can someone tell me the name of the function I must use, I will look for the
> rest in the php dictionary.
Say you're using MySQL...
$userid = 'bob';
$sql = "select userid from user where userid='$userid'";
$st = mysql_query($sql);
if (mysql_num_rows($st))
{
print "<p>UserID <b>$userid</b> already in use.</p>";
}
else
{
print '<p>Now adding you to the database...</p>';
// ...
}
miguel