Warning: mysql_num_rows(): supplied argument is not a valid MySQL result

resource on line 11…ok

I am fairly new to php, starting to get the hang of it a bit, but I run into this error on the login page after you hit submit, here is the code…

<?php
if ($_POST[‘email’]) {

include_once “connect_to_mysql.php”;
$email = stripslashes($_POST[‘email’]);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace(“[^A-Za-z0-9]”, “”, $_POST[‘password’]);
$password = md5($password);
$sql = mysql_query(“SELECT * FROM members WHERE email=‘$email’ AND password=‘$password’ AND emailactivated=‘1’”);
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$id = $row[“id”];
session_register(‘id’);
$_SESSION[‘id’] = $id;
$username = $row[“username”];
session_register(‘username’);
$_SESSION[‘username’] = $username;
mysql_query(“UPDATE members SET lastlogin=now() WHERE id=‘$id’”);
header(“location: member_profile.php?id=$id”);
exit();
}
} else {
print ‘<br /><br /><font color=“#FF0000”>No match in our records, try again </font><br />
<br /><a href=“login.php”>Click here</a> to go back to the login page.’;
exit();
}
}
?>

Being new to php, I can’t be sure, but I think the highlighted line is causing the problem

I have been searching the net for hours trying to find a solution.

I have also checked my db and tables, everything is spelled correctly, no caps versus lowers, everything checks out, but the error continues.

you can check it out yourself

Digital Music Distribution

The error indicates the query has ended with an error.
To know what error, you can change the red line in:


$query = "
  SELECT * 
  FROM members 
  WHERE email='$email' 
  AND password='$password' 
  AND emailactivated='1'
"; 
$sql = mysql_query($query) or die("mysql error : " . mysql_error() . " in query $query"); 

ok, I put that line in and I get the error

mysql error:Query was empty in query…

so I have no idea, I know it’s not because the db is empty, because I go in and look and the entries are there…so I have no idea

It’s two lines actually…
Can you post the changed script?

sure

<?php
if ($_POST[‘email’]) {

include_once “connect_to_mysql.php”;
$email = stripslashes($_POST[‘email’]);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace(“[^A-Za-z0-9]”, “”, $_POST[‘password’]);
$password = md5($password);
$query = “SELECT * FROM members WHERE email=‘$email’ AND password=‘$password’ AND emailactivated=‘1’”;
$sql = mysql_query($query) or die(“mysql error : " . mysql_error() . " in query $query”)
;
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$id = $row[“id”];
session_register(‘id’);
$_SESSION[‘id’] = $id;
$username = $row[“username”];
session_register(‘username’);
$_SESSION[‘username’] = $username;
mysql_query(“UPDATE members SET lastlogin=now() WHERE id=‘$id’”);
header(“location: member_profile.php?id=$id”);
exit();
}
} else {
print ‘<br /><br /><font color=“#FF0000”>No match in our records, try again </font><br />
<br /><a href=“login.php”>Click here</a> to go back to the login page.’;
exit();
}
}
?>

Ok, and that gives you this error?

mysql error:Query was empty in query...

With those three dots at the end?

no I put those three dots there when I typed the message

sorry about that

here I’ll copy and paste the error from the page,

mysql error : Query was empty in query

Sorry, but if you have these two lines in your code


$query = "SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'";
$sql = mysql_query($query) or die("mysql error : " . mysql_error() . " in query $query");

Then $query has to have a value. It can’t be empty.

that’s what it says, I’m testing it live, not locally

Try this


$query = "SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'";
echo "query: $query<br />";
$sql = mysql_query($query) or die("mysql error : " . mysql_error() . " in query $query");

ok, now I got this error

mysql error : Unknown column ‘emailactivated’ in ‘where clause’ in query SELECT * FROM members WHERE email=‘k.jh’ AND password=‘b18731ee9d34eab6c644f6c152c8daae’ AND emailactivated=‘1’

oh, wait

ok, it’s working now, there was an error in my database, i had it ‘emailactivate’, it needed to be ‘emailactivated’

thanks for your help guido,