View Full Version : Help with mysql error

01-10-2010, 07:48 AM
here is my code:


$desire_schedule = '0';


echo '<br /><div align="center">';

$checked = $_POST['schedman'];
if($checked == 'Yes'){
$desire_schedule = '1';
else {
$desire_schedule = '0';

$stop = "false";
echo '<br /><div align="center">';

$names1 = trim($_POST['selected']);
$admin2_query = mysql_query("SELECT * FROM admins WHERE name = '$names1'");
$admin2_data = mysql_num_rows($admin2_query);
$admin_query = mysql_query("SELECT * FROM accounts WHERE name = '$names1'");
$admin_data = mysql_fetch_array($admin_query);
$usname = $admin_data['name'];
$email = $admin_data['email'];
$password = $admin_data['password'];
$zpassword = sha1($password);
$mpassword = md5($zpassword);

if($admin2_data != '0'){
echo '<font color="red">' . $usname . ' is already a schedule manager, please log into the schedule manager screen to erase them from allowable schedule managers';
$stop = "true";
else if($stop == "false"){
if($desire_schedule == '1'){
mysql_query("INSERT INTO `admins` (`username`, `password`, `email`) VALUES ('$usname', '$mpassword', '$email')");
echo '<font color="green">' . $usname . ' is now a schedule manager.';
$stop = "true";
} else if($stop == "false"){

if($desire_schedule == '0'){
$stop = "true";
echo '</font></div>';


the connection to mysql is working just fine, when I put it on my site and attempt to use it, it outputs:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in update_users.php on line 77

I tried many google searches, and have been battling this for over 12 hours (I'm not very good at PHP or mysql i guess XD)

any input is greatly appreciated. thank you =)

01-10-2010, 08:13 AM
Could you post the contents of line 77 in the indicated script please. I quickly reviewed your script and couldn't find any errors with the mysql_num_rows argument, so I was curious, maybe you have been looking in the wrong place?

01-10-2010, 08:16 AM
Sounds like the query might be failing.

Try modifying the query that you are trying to get the number of rows on like so:

$admin2_query = mysql_query("SELECT * FROM admins WHERE name = '$names1'") or die(mysql_error());

That will print out the mysql error message if the query fails.

01-10-2010, 09:10 AM
thanks to "oracleguy" I was able to figure it out, thank you =)

01-10-2010, 11:39 AM
If you ever get an error with mysql you should use mysql_error() to work out what is wrong. It gives you a pretty good idea immediately
Also, you should use

$query = "SELECT ... $variable ...";
This means that if your query isn't working as expected you can just use echo $query between those two lines and it will output what query is being run (when the variables have been inserted into the query)