Re: To check for existing user in database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 $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@xxxxxxxxxxx");
			  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


--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux