• PHP Help PHP Newbies
  • Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

hi im getting an error that says Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in/home/pickurau/public_html/classes/Lib/Query.php on line 27

can anyone tell me how to fix this?

heres the code

<?php
class Lib_Query extends Lib_DbConnect
{
var $rs;
var $totrows;
var $records;

/**
 * Enter description here...
 *
 * @param string $sql
 * @param array $fields
 * @return boolean
 */
function executeQuery($sql, $fields = array())
{
	//echo $sql,"<br/>";
	if(substr_count($sql,'#')!=count($fields))
		return false;
	if(count($fields)>0)
		$sql = $this->makeQuery($sql,$fields);	// Security::makeQuery();
	$i=0;

	[B]$this->rs = mysql_query($sql);

	if(!mysql_affected_rows()|| mysql_num_rows($this->rs) < 1)
		return false;
	else
	{[/B]
		$this->totrows = mysql_num_rows($this->rs);
		while($fetch = mysql_fetch_array($this->rs))
		{
			$this->records[$i] = $fetch;
			$i++;
		}
		for($i=0;$i<count($this->records);$i++)
		{
			foreach ($this->records[$i] as $key=>$item)
			{
				if(is_numeric($key))
					unset($this->records[$i][$key]);
			}
		}
		return true;
	}
}

/**
 * @param string $sql
 * @return boolean
 */
function updateQuery($sql, $fields=array())
{

	if(substr_count($sql,'#')!=count($fields))
		return false;
	if(count($fields)>0)
		$sql = $this->makeQuery($sql,$fields);	// Security::makeQuery();

	$this->rs = mysql_query($sql);
	if(!$this->rs)
		return false;
	else
		return true;
}	

}
?>

    uncomment your ...

    //echo $sql,"<br/>";

    ... statement and try pasting the result into a console or phpMyAdmin, etc. and see if the query works without throwing any errors.

    If you want to do it in code, just throw in:

    echo mysql_error();

    after...

    $this->rs = mysql_query($sql);

      There are lots of other PHP's classes for interacting with MySQL database, .. try using MYSQLI, or PHP PDO

        Write a Reply...