Page 1 of 1

Counting rows for email in MySQL, mysql_num_rows !working

Posted: Sun Aug 03, 2008 2:15 pm
by JAB Creations
I'm having trouble getting mysql_num_rows to work in conjunction with using it to count the total number of rows returned to determine if the email address exists in the database...

Code: Select all

$mysql_register_0 = mysql_query("SELECT email FROM `public_accounts` WHERE email = '$email'", $db);
echo mysql_num_rows(mysql_query($mysql_register_0, $db));
I'm just trying to see if the variable equals '0' or '1' or true/false. What am I doing wrong?

Re: Counting rows for email in MySQL, mysql_num_rows !working

Posted: Sun Aug 03, 2008 2:38 pm
by jaoudestudios
What result are you getting?

Change the sql query too...(but dont think that will solve your problem, but will be more efficient)

Code: Select all

 
"SELECT email FROM `public_accounts` WHERE email = '".$email."'"
 

Re: Counting rows for email in MySQL, mysql_num_rows !working

Posted: Sun Aug 03, 2008 2:54 pm
by JAB Creations
I have been trying to clean up code before I get in to templates and such. For example instead of using die I'll merely assign a MySQL error to $_SESSION['error'] and spit it out if necessary....so I've been transitioning code to be a bit more manageable. Some of the code may be crap...but until I get this to work everything else is of secondary concern.

Here is what I have thus far...

Code: Select all

if ($_POST['formis'] == 'registration_start')
{
 $db = mysql_connect($mysql_host, $mysql_name, $mysql_pass);
 if (!$db) {echo 'Could not connect to the database: '.mysql_error();}
 $db_selected = mysql_select_db("public_accounts", $db);
 
 $username = mysql_real_escape_string($_POST['username']);
 $password = mysql_real_escape_string($_POST['password']);
 $email = $_POST['email'];
 $date_time = date("Y:m:d:H:i:s");
 $activation_key = rand(101, 998);
 $_SESSION['username'] = $_POST['username'];
 $_SESSION['activation_key'] = $activation_key;
 $mysql_register_0 = mysql_query("SELECT email FROM `public_accounts` WHERE email = '".$email."'", $db);
 
 
 if (mysql_num_rows($mysql_register_0) != "0") {header("location:____.php?error=email_registered");}
 else
 {
 
 $mysql_register = mysql_query("INSERT INTO public_accounts (username, password, email, activation_key, date_0) VALUES ('$username', '$password', '$email', '$activation_key', NOW())");
 if (!$mysql_register) {$_SESSION['error'] = mysql_error(); header("location:____.php?error=email_registered");}
 else
  {
   header("location:____.php?activate");
   $emailfrom = 'no_reply__at__jabcreations.com';
   $body = "Click the link below to complete your registration at JAB Creations.\nhttp://www.____.php?activate=".$activation_key;
   $subject = 'JAB Creations - Registration Activation Code = '.$activation_key;
   $success = mail($_POST['email'], $subject, $body, "From: <$emailfrom>");
  }
 }
}

Re: Counting rows for email in MySQL, mysql_num_rows !working

Posted: Sun Aug 03, 2008 3:32 pm
by JAB Creations
Never mind...like I said I was cleaning up crap code and I forgot to do a check...everything is working now.