To check for existing user in database
| From: | Chris Carter | Date: | Thu, 15 Jan 2009 17:46:21 +0000 |
| Subject: | To check for existing user in database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-286441@lists.php.net to get a copy of this message | ||
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
$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 into
owners (emailAddress, confEmail, password,
confPassword) VALUES ('$emailAddress', '$confEmail', '$password',
'$confPassword')";
if(mysql_query($sql))
{
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.