Page 1 of 1

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

Posted: Mon Jun 05, 2006 6:23 pm
by a94060
Hi,this may seem like a stupid error but for some reason i cannot seem to find the problem to it.
Error is :Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/noob/public_html/index.php on line 51

The part which this corralates to is

Code: Select all

$sql = "SELECT * FROM updates";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
		  if($rows == 0) {
		  echo 'NO Updates in the Database right now';
		  }
		  else {
		  		while($result = mysql_fetch_array($result)) {
		  		echo 'Date:' .$result['date'];
		  		echo 'Time:' .$result['time'];
		  		}
		}
im pretty sire this is a simple fis,i just cant seem to find the error.

Posted: Mon Jun 05, 2006 6:26 pm
by daedalus__
You might want to use mysql_affected_rows() instead.

Re: Warning: mysql_num_rows(): supplied argument is not a va

Posted: Mon Jun 05, 2006 6:29 pm
by Christopher
Remember to always check for errors:

Code: Select all

$sql = "SELECT * FROM updates";
$result = mysql_query($sql);
if ($errmsg = mysql_error($result)) {
    echo "Error: $errmsg";
} else {
        $rows = mysql_num_rows($result);
		  if($rows == 0) {
		      echo 'NO Updates in the Database right now';
		  } else {
		  	while($result = mysql_fetch_array($result)) {
		  		echo 'Date:' .$result['date'];
		  		echo 'Time:' .$result['time'];
		  	}
		}
}

Posted: Mon Jun 05, 2006 6:32 pm
by RobertGonzalez
Dadgummit arborint, you beat me to it :oops: ...

mysql_affect_rows is for INSERT/UPDATE/DELETE queries. Try this and see what pops out...

Code: Select all

<?php
$sql = "SELECT * FROM updates";
$result = mysql_query($sql) or die("Could not run the query: " . mysql_error());
$rows = mysql_num_rows($result);
if ($rows == 0) {
    echo 'NO Updates in the Database right now';
}
else {
    while($result = mysql_fetch_array($result)) {
        echo 'Date:' .$result['date'];
        echo 'Time:' .$result['time'];
    }
}
?>

Posted: Mon Jun 05, 2006 6:40 pm
by a94060
Everah wrote:Dadgummit arborint, you beat me to it :oops: ...

mysql_affect_rows is for INSERT/UPDATE/DELETE queries. Try this and see what pops out...

Code: Select all

<?php
$sql = "SELECT * FROM updates";
$result = mysql_query($sql) or die("Could not run the query: " . mysql_error());
$rows = mysql_num_rows($result);
if ($rows == 0) {
    echo 'NO Updates in the Database right now';
}
else {
    while($result = mysql_fetch_array($result)) {
        echo 'Date:' .$result['date'];
        echo 'Time:' .$result['time'];
    }
}
?>
i ran that query and it spit out:
Could not run the query: No database selected
i know it sounds very simple but i have everything correct in my sql config file. i am absoulutly 100% sure about this,but here it is anyways.

Code: Select all

<?PHP

/******************************
SQL Connection Files
Edit what you want here. 
It will be included in other files for connecting.
******************************/

$host = "localhost";
$user = "***l"; //sql username
$pass = "*pass*"; //sql password
$db = "**DB**" ; //database name
mysql_connect($host,$user,$pass);
mysql_select_db($db) or mysql_error();
?>

Posted: Mon Jun 05, 2006 6:42 pm
by daedalus__

Code: Select all

mysql_connect($host,$user,$pass) or die('Could not connect: '.mysql_error()); 
mysql_select_db($db) or die('Could not select DB: '.mysql_error());

Posted: Mon Jun 05, 2006 6:49 pm
by a94060
ok,i found the problem,it was just in cpanel...i forgot to add the sql user...sorry all,but thanks for hlep