Re: Checking for 2 unique row contents
| From: | Adam Royle | Date: | Wed, 27 Mar 2002 09:06:46 +0000 |
| Subject: | Re: Checking for 2 unique row contents | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-17939@lists.php.net to get a copy of this message | ||
Simple.... do these checks.... and you'll be sweet as a nut
Adam
<?php
$sql = "SELECT nickname FROM tblUsers WHERE nickname = '$nickname''";
$result = mysql_query($sql);
$sql = "SELECT email FROM tblUsers WHERE email = '$email'";
$result2 = mysql_query($sql);
if (mysql_num_rows($result)){
$error[] = "That nickname is already chosen";
}
if (mysql_num_rows($result2)){
$error[] = "That username is already chosen";
}
if (!$error){
// do the inserting here
}
?>
// you might have this at the top of your form to show the error messages
<?php
if ($error){
echo "<p class=\"msg\">\n";
for($i=0;$i<count($error);$i++){
echo "$error[$i] . "<br>\n";
}
echo "</p>\n";
}
?>
Hi all I am trying to create a registration area that uses a nickname and email pair. I need both to be unique. So how do I that either do not already exist then if unique insert into db. So if nickname exist then error = "sorry..." if email exist then error = "sorry..." else must be unique insert. I have been trying for hours know but cant get the twin check to work. Can get single check to work though. I thank you in advance for any thoughts or code examples Dave Carrera Php Developer http://davecarrera.freelancers.net http://www.davecarrera.com