Re: To check for existing user in database
| From: | tedd | Date: | Thu, 15 Jan 2009 22:17:17 +0000 |
| Subject: | Re: To check for existing user in database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-286470@lists.php.net to get a copy of this message | ||
At 9:46 AM -0800 1/15/09, Chris Carter wrote:
Chris:
That's not the way I would do it. After establishing a connection with the database, I would use the query:
$query "SELECT email FROM owners WHERE email = '$emailAddress' ":
$result = mysql_query($query) or die(mysql_error());
if(mysql_affected_rows())
{
// then report a duplicate email/record.
}
else
{
// else insert a new record in the dB.
}
HTH's
tedd
---
Hi, I know this is very basic question, this is so because I am a basic programmer struggling to make things work. Where in this code should I be trying to check if the user already exists and throw an error saying "The user already exists ding ding ding". The check has to be done with the emailAddress: <? // database information-- ------- http://sperling.com http://ancientstones.com http://earthstones.com$host = 'xxx'; $user = 'xxx';$password = 'xxx'; $dbName = 'xxx';if ($_POST['submit']) {// connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // insert new entry in the database if entry submitted $emailAddress = $_POST['emailAddress']; $confEmail = $_POST['confEmail']; $password = $_POST['password']; $confPassword = $_POST['confPassword'];$body = "Some email text"; // insert new entry into database $sql = "insert intoconfPassword) VALUES ('$emailAddress', '$confEmail', '$password', '$confPassword')"; if(mysql_query($sql))owners(emailAddress, confEmail, password,{ mail($emailAddress, "Thank you for registering!", $body, "From:someone@someone.com"); header("Location: thankYou.php"); } else { die("Error! Could not insert values".mysql_error()); } } ?> Thanks in advance, Chris -- View this message in context: http://www.nabble.com/To-check-for-existing-user-in-database-tp21483013p21483013.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php