i am having this error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jinii/public_html/beta/includes/db.class.php on line 79

db.class.php contains this code:

<?

class Db
{

function RemoveDoubleQoute($content)
{
	$content = str_replace('"',"'",$content);

	return $content;
}
//var $new_article_id;

//*****Function to remove Apostrophy from a string************
function RemoveApostophy($content)
{
$content = str_replace("'","`",$content);

	return $content;
}
//var $new_article_id;
/**
*	Funciton Name: 	Constructor
*	Parameters:		No Parameters
*/

var $query;

//******************************************** RECORD SET *************************************
function record_set($table, $condition, $sort_field, $order_by, $limit, $fields = '
', $inner_join='', $which='limit')
{
$fields = explode(',',$fields);
$string = "";
for ($i = 0; $i < count($fields); $i++) {

$string .= $fields[$i] . ",";
}
$string = $this->RemoveApostophy(substr($string ,0,-1));

// $values .= "$k='".$this->RemoveApostophy($v)."',";

				if ($condition != ''){
					$condition = ' where '.$condition. ' ' ;
				}
				if ($sort_field != ''){
					$sort_field = ' order by '.$sort_field. ' ' . $order_by.' ' ;
				}
				if ($limit != ''){
					$limit = ' limit '.$limit. ' ' ;
				}
				if ($inner_join != ''){
					$inner_join = ' Inner Join  '.$inner_join. ' ' ;
				}
	$rocord_set = array();
	if ($which == 'limit'){
		$q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field $limit";
		$record_set_normal = mysql_query($q);

		$record_set['limit'] = $record_set_normal;
	}elseif($which == 'total'){
	 	$q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field";
		$record_set_total = mysql_query($q);

		$record_set['total'] = $record_set_total;
	}else{
		$q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field $limit";
		$record_set_normal = mysql_query($q);
		$q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field";
		$record_set_total = mysql_query($q);


		$record_set['limit'] = $record_set_normal;
		$record_set['total'] = $record_set_total;
	}
return $record_set;
}

//********************************************* RETURN VALUES ******************************
function return_values($record_set)
{
if(mysql_num_rows($record_set))
{
$rows = 0;
$info=array();
$tmp_array = array();
while($fields = mysql_fetch_array($record_set))
{
$columns = mysql_num_fields($record_set);
$string = '';
for ($x=0; $x<$columns; $x++) {
$tmp_array[mysql_field_name($record_set, $x)] = $fields[$x];
$info[$rows]=$tmp_array;
}
$rows = $rows+1;
}
return $info;
}else{
return false;
}
}
//
***************************************************************** Update Record *****
function update_record($table, $info, $condition) //update user any fields
{
$values = "";
foreach($info as $k=>$v)
{
if($k != 'Submit' AND $k != 'submit')
$values .= "$k=\"$v\",";
}

	  // $values = substr($values,0,-1);
	  $values = $this->RemoveApostophy(substr($values ,0,-1));

	  $query = "UPDATE ".PREFIX."$table 
		      SET  
			  $values
			  WHERE $condition
			  ";
		   if(mysql_query($query) )
			  	return true;
		   else
		   		return false;
   }

//************************************** ADD RECORD ******************************************
//function add_record($table, $fields, $values){

//
// if($fields != ''){
// $fields = explode(',',$fields);
// $string = "(";
// for ($i = 0; $i < count($fields); $i++) {

// $string .= $fields[$i] . ",";
// }
// $string = substr($string,0,-1);
// $string .= ")";
// }
// if($values != ''){
// $values = explode(',',$values);
// $data = "";
// for ($i = 0; $i < count($values); $i++) {

// $data .= "'" . $values[$i] . "',";
// }
// $data = substr($data ,0,-1);
// }
// $q = "insert into $table $string values($data)";
//
// $success = mysql_query($q);
// if($success)
// return true;
// else
// return false;
// }

	function add_record($table, $info)
	{
	   $param = "";
	   $values = "";
	   foreach($info as $k=>$v)
	   {
			if($v != "" AND $k != 'Submit' AND $k != 'submit')
			{
			  $param .= $k.',';
			  $values .= "\"".$v."\",";

			}
	   }
	   $param = substr($param,0,-1);
	   //$values = substr($values,0,-1);
	   $values = $this->RemoveApostophy(substr($values ,0,-1));
	   $query = "insert into ".PREFIX."$table ($param) values($values)";
	   		if(mysql_query($query) )
		   		return true;
			else
				return false;
	}

//**************************************************************************** Delete Record
function delete_record($table, $condition){
$query = "DELETE FROM ".PREFIX. "$table WHERE( $condition )";
if(mysql_query($query))
return true;
else
return false;
}
//
************************************* PAGINAITON ******************************************
function pagination($sql_result, $cur_page, $records_per_page, $link, $link_class, $link_text_patern = "[%s]"){

  $this -> sql_result        = $sql_result;
  $this -> sql_num_rows      = @mysql_num_rows($this -> sql_result);
  $this -> sql_num_cols      = @mysql_num_fields($this -> sql_result);
  $this -> link              = $link;
  $this -> link_text_patern  = $link_text_patern;
  $this -> cur_page          = $cur_page;
  $this -> link_class        = $link_class;
  $this -> records_per_page  = $records_per_page;
  $this -> total_pages       = ceil($this -> sql_num_rows / $this -> records_per_page);
  $this -> val_min_de_afisat = 0;
  $this -> val_man_de_afisat = 0;

}

function show_pagination() {
  if ($this -> total_pages > $this -> cur_page) {
        $this -> val_min_de_afisat = $this -> cur_page - ($this -> cur_page % 10);
        $this -> val_max_de_afisat = $this -> val_min_de_afisat + 10;

        if ($this -> cur_page > 9) echo ("<a href=\"" . $this -> link . ($this -> val_min_de_afisat-1) . "\" class='".$this -> link_class."'> << </a>\n");
        for ($i = $this -> val_min_de_afisat; $i < min($this -> val_max_de_afisat, $this -> total_pages); $i++) {

           if ($this -> cur_page < $i)  printf ("<a href=\"" . $this -> link . ($i) . "\"  class='".$this -> link_class."'>" . $this -> link_text_patern . "</a>\n", $i+1);
           if ($this -> cur_page == $i) printf ("<span class='current'>". $this -> link_text_patern . "</span> \n", $i+1);
           if ($this -> cur_page > $i)  printf ("<a href=\"" . $this -> link . ($i) . "\"  class='".$this -> link_class."'>" . $this -> link_text_patern . "</a>\n", $i+1);
        }
        if ($this -> val_max_de_afisat < $this -> total_pages) printf ("<a href=\"" . $this -> link . ($i) . "\" class='".$this -> link_class."'> >> </a>\n", $i+1);
  }

}

}
//************************************************************* Redirect URl *************************
function url($url){
echo("<script language ='JavaScript'>\n");
echo("document.location ='$url';\n");
echo("</script>\n");
}
//
************************************************************************* Alert Message ****************************
function
alert($msg){
echo("<script language ='JavaScript'>\n");
echo("alert('$msg');\n");
echo("</script>\n");
}
?>

thanks in advance

    Try adding or die(mysql_error()) to the end of the query before the mysql_num_rows call

      sorry i am new and did'nt get you =(

        Ok, I assume you didn't write that code then.

        Check your SQL query. The error is saying that you are trying to get results from an invalid resource (i.e. an invalid query).

          10 days later

          i just want to know , if i would reupload the fresh files so it could be fixed? or its a database sql query error? actually there is a programmer who is working on my project , he is pissing meh off since 4 months for the project , making excuses and stuff. he is saying that its not related to me, he is saying when i got this project there was no errros , and he is saying yew can upload fresh files and check that this error comes to me or not , but i far as i know its nothing related to files, he injected some bad queries in sql , right?

            there are 2 places with mysql_num_rows.

            paste in these lines right before those with mysql_num_rows and tell us the result:
            a) in this function: function return_values($record_set) ) write:

            var_dump($recordset);

            in this function: function pagination($sql_result, $cur_page, $records_per_page, $link, $link_class, $link_text_patern = "[%s]")) write:

            var_dump($this -> sql_result);

            And please in your post replace [ code ] [ /code ] with [ php ] [ /php ] (without the extra spacing that I added...)

              Bjom;10920350 wrote:

              there are 2 places with mysql_num_rows.

              paste in these lines right before those with mysql_num_rows and tell us the result:
              a) in this function: function return_values($record_set) ) write:

              var_dump($recordset);

              in this function: function pagination($sql_result, $cur_page, $records_per_page, $link, $link_class, $link_text_patern = "[%s]")) write:

              var_dump($this -> sql_result);

              And please in your post replace [ code ] [ /code ] with [ php ] [ /php ] (without the extra spacing that I added...)

              now im having this error on whole website

              Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /home/jinii/public_html/beta/includes/db.class.php on line 77
              

              and the code is now in db.class.php:

              <?
              
              class Db
              {
              
              
              function RemoveDoubleQoute($content)
              {
              	$content = str_replace('"',"'",$content);
              
              	return $content;
              }
              //var $new_article_id;
              
              //********Function to remove Apostrophy from a string***************
              	function RemoveApostophy($content)
              	{
              		$content = str_replace("'","`",$content);
              
              	return $content;
              }
              //var $new_article_id;
              /**
              *	Funciton Name: 	Constructor
              *	Parameters:		No Parameters
              */
              
              var $query;
              //*********************************************** RECORD SET *****************************************
              	function record_set($table, $condition, $sort_field, $order_by, $limit, $fields = '*', $inner_join='', $which='limit')
              	{
              		$fields = explode(',',$fields);
              		$string = "";
              		for ($i = 0; $i < count($fields); $i++) {       
              $string .= $fields[$i] . ","; } $string = $this->RemoveApostophy(substr($string ,0,-1)); // $values .= "$k='".$this->RemoveApostophy($v)."',"; if ($condition != ''){ $condition = ' where '.$condition. ' ' ; } if ($sort_field != ''){ $sort_field = ' order by '.$sort_field. ' ' . $order_by.' ' ; } if ($limit != ''){ $limit = ' limit '.$limit. ' ' ; } if ($inner_join != ''){ $inner_join = ' Inner Join '.$inner_join. ' ' ; } $rocord_set = array(); if ($which == 'limit'){ $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field $limit"; $record_set_normal = mysql_query($q); $record_set['limit'] = $record_set_normal; }elseif($which == 'total'){ $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field"; $record_set_total = mysql_query($q); $record_set['total'] = $record_set_total; }else{ $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field $limit"; $record_set_normal = mysql_query($q); $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field"; $record_set_total = mysql_query($q); $record_set['limit'] = $record_set_normal; $record_set['total'] = $record_set_total; } return $record_set; } //************************************************ RETURN VALUES ************************************ var_dump($recordset); function return_values($record_set) ) { if(mysql_num_rows($record_set)) { $rows = 0; $info=array(); $tmp_array = array(); while($fields = mysql_fetch_array($record_set)) { $columns = mysql_num_fields($record_set); $string = ''; for ($x=0; $x<$columns; $x++) { $tmp_array[mysql_field_name($record_set, $x)] = $fields[$x]; $info[$rows]=$tmp_array; } $rows = $rows+1; } return $info; }else{ return false; } } //*********************************************************************** Update Record ******** function update_record($table, $info, $condition) //update user any fields { $values = ""; foreach($info as $k=>$v) { if($k != 'Submit' AND $k != 'submit') $values .= "$k=\"$v\","; } // $values = substr($values,0,-1); $values = $this->RemoveApostophy(substr($values ,0,-1)); $query = "UPDATE ".PREFIX."$table SET $values WHERE $condition "; if(mysql_query($query) ) return true; else return false; } //***************************************** ADD RECORD ********************************************* //function add_record($table, $fields, $values){
              // // if($fields != ''){ // $fields = explode(',',$fields); // $string = "("; // for ($i = 0; $i < count($fields); $i++) {
              // $string .= $fields[$i] . ","; // } // $string = substr($string,0,-1); // $string .= ")"; // } // if($values != ''){ // $values = explode(',',$values); // $data = ""; // for ($i = 0; $i < count($values); $i++) {
              // $data .= "'" . $values[$i] . "',"; // } // $data = substr($data ,0,-1); // } // $q = "insert into $table $string values($data)"; // // $success = mysql_query($q); // if($success) // return true; // else // return false; // } function add_record($table, $info) { $param = ""; $values = ""; foreach($info as $k=>$v) { if($v != "" AND $k != 'Submit' AND $k != 'submit') { $param .= $k.','; $values .= "\"".$v."\","; } } $param = substr($param,0,-1); //$values = substr($values,0,-1); $values = $this->RemoveApostophy(substr($values ,0,-1)); $query = "insert into ".PREFIX."$table ($param) values($values)"; if(mysql_query($query) ) return true; else return false; } //******************************************************************************* Delete Record **** function delete_record($table, $condition){ $query = "DELETE FROM ".PREFIX. "$table WHERE( $condition )"; if(mysql_query($query)) return true; else return false; } //***************************************** PAGINAITON ********************************************* var_dump($this -> sql_result); function pagination($sql_result, $cur_page, $records_per_page, $link, $link_class, $link_text_patern = "[%s]")){ $this -> sql_result = $sql_result; $this -> sql_num_rows = @mysql_num_rows($this -> sql_result); $this -> sql_num_cols = @mysql_num_fields($this -> sql_result); $this -> link = $link; $this -> link_text_patern = $link_text_patern; $this -> cur_page = $cur_page; $this -> link_class = $link_class; $this -> records_per_page = $records_per_page; $this -> total_pages = ceil($this -> sql_num_rows / $this -> records_per_page); $this -> val_min_de_afisat = 0; $this -> val_man_de_afisat = 0; } function show_pagination() { if ($this -> total_pages > $this -> cur_page) { $this -> val_min_de_afisat = $this -> cur_page - ($this -> cur_page % 10); $this -> val_max_de_afisat = $this -> val_min_de_afisat + 10; if ($this -> cur_page > 9) echo ("<a href=\"" . $this -> link . ($this -> val_min_de_afisat-1) . "\" class='".$this -> link_class."'> << </a>\n"); for ($i = $this -> val_min_de_afisat; $i < min($this -> val_max_de_afisat, $this -> total_pages); $i++) { if ($this -> cur_page < $i) printf ("<a href=\"" . $this -> link . ($i) . "\" class='".$this -> link_class."'>" . $this -> link_text_patern . "</a>\n", $i+1); if ($this -> cur_page == $i) printf ("<span class='current'>". $this -> link_text_patern . "</span> \n", $i+1); if ($this -> cur_page > $i) printf ("<a href=\"" . $this -> link . ($i) . "\" class='".$this -> link_class."'>" . $this -> link_text_patern . "</a>\n", $i+1); } if ($this -> val_max_de_afisat < $this -> total_pages) printf ("<a href=\"" . $this -> link . ($i) . "\" class='".$this -> link_class."'> >> </a>\n", $i+1); } } } //**************************************************************** Redirect URl ******************************* function _url($url){ echo("<script language ='JavaScript'>\n"); echo("document.location ='$url';\n"); echo("</script>\n"); } //******************************************************************************* Alert Message ******************************* function _alert($msg){ echo("<script language ='JavaScript'>\n"); echo("alert('$msg');\n"); echo("</script>\n"); } ?>

                the vardump needs to be inside the function right in front of the line with the num rows...

                change this:

                var_dump($recordset); function return_values($record_set) ) 
                {         
                if(mysql_num_rows($record_set))

                to that:

                function return_values($record_set) ) 
                {         
                var_dump($recordset);
                if(mysql_num_rows($record_set))

                  now having this error :

                  Notice: Undefined variable: recordset in /home/jinii/public_html/beta/includes/db.class.php on line 79
                  NULL 
                  Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jinii/public_html/beta/includes/db.class.php on line 80
                  
                  Notice: Undefined variable: recordset in /home/jinii/public_html/beta/includes/db.class.php on line 79
                  NULL 
                  Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jinii/public_html/beta/includes/db.class.php on line 80

                  and db.class.php contains this now:

                  <?
                  
                  class Db
                  {
                  
                  
                  function RemoveDoubleQoute($content)
                  {
                  	$content = str_replace('"',"'",$content);
                  
                  	return $content;
                  }
                  //var $new_article_id;
                  
                  //********Function to remove Apostrophy from a string***************
                  	function RemoveApostophy($content)
                  	{
                  		$content = str_replace("'","`",$content);
                  
                  	return $content;
                  }
                  //var $new_article_id;
                  /**
                  *	Funciton Name: 	Constructor
                  *	Parameters:		No Parameters
                  */
                  
                  var $query;
                  //*********************************************** RECORD SET *****************************************
                  	function record_set($table, $condition, $sort_field, $order_by, $limit, $fields = '*', $inner_join='', $which='limit')
                  	{
                  		$fields = explode(',',$fields);
                  		$string = "";
                  		for ($i = 0; $i < count($fields); $i++) {       
                  $string .= $fields[$i] . ","; } $string = $this->RemoveApostophy(substr($string ,0,-1)); // $values .= "$k='".$this->RemoveApostophy($v)."',"; if ($condition != ''){ $condition = ' where '.$condition. ' ' ; } if ($sort_field != ''){ $sort_field = ' order by '.$sort_field. ' ' . $order_by.' ' ; } if ($limit != ''){ $limit = ' limit '.$limit. ' ' ; } if ($inner_join != ''){ $inner_join = ' Inner Join '.$inner_join. ' ' ; } $rocord_set = array(); if ($which == 'limit'){ $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field $limit"; $record_set_normal = mysql_query($q); $record_set['limit'] = $record_set_normal; }elseif($which == 'total'){ $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field"; $record_set_total = mysql_query($q); $record_set['total'] = $record_set_total; }else{ $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field $limit"; $record_set_normal = mysql_query($q); $q = "select $string from ".PREFIX."$table $condition $inner_join $sort_field"; $record_set_total = mysql_query($q); $record_set['limit'] = $record_set_normal; $record_set['total'] = $record_set_total; } return $record_set; } //************************************************ RETURN VALUES ************************************ function return_values($record_set) { var_dump($recordset); if (mysql_num_rows($record_set)) { $rows = 0; $info=array(); $tmp_array = array(); while($fields = mysql_fetch_array($record_set)) { $columns = mysql_num_fields($record_set); $string = ''; for ($x=0; $x<$columns; $x++) { $tmp_array[mysql_field_name($record_set, $x)] = $fields[$x]; $info[$rows]=$tmp_array; } $rows = $rows+1; } return $info; }else{ return false; } } //*********************************************************************** Update Record ******** function update_record($table, $info, $condition) //update user any fields { $values = ""; foreach($info as $k=>$v) { if($k != 'Submit' AND $k != 'submit') $values .= "$k=\"$v\","; } // $values = substr($values,0,-1); $values = $this->RemoveApostophy(substr($values ,0,-1)); $query = "UPDATE ".PREFIX."$table SET $values WHERE $condition "; if(mysql_query($query) ) return true; else return false; } //***************************************** ADD RECORD ********************************************* //function add_record($table, $fields, $values){
                  // // if($fields != ''){ // $fields = explode(',',$fields); // $string = "("; // for ($i = 0; $i < count($fields); $i++) {
                  // $string .= $fields[$i] . ","; // } // $string = substr($string,0,-1); // $string .= ")"; // } // if($values != ''){ // $values = explode(',',$values); // $data = ""; // for ($i = 0; $i < count($values); $i++) {
                  // $data .= "'" . $values[$i] . "',"; // } // $data = substr($data ,0,-1); // } // $q = "insert into $table $string values($data)"; // // $success = mysql_query($q); // if($success) // return true; // else // return false; // } function add_record($table, $info) { $param = ""; $values = ""; foreach($info as $k=>$v) { if($v != "" AND $k != 'Submit' AND $k != 'submit') { $param .= $k.','; $values .= "\"".$v."\","; } } $param = substr($param,0,-1); //$values = substr($values,0,-1); $values = $this->RemoveApostophy(substr($values ,0,-1)); $query = "insert into ".PREFIX."$table ($param) values($values)"; if(mysql_query($query) ) return true; else return false; } //******************************************************************************* Delete Record **** function delete_record($table, $condition){ $query = "DELETE FROM ".PREFIX. "$table WHERE( $condition )"; if(mysql_query($query)) return true; else return false; } //***************************************** PAGINAITON ********************************************* function pagination($sql_result, $cur_page, $records_per_page, $link, $link_class, $link_text_patern = "[%s]"){ var_dump($this -> sql_result); $this -> sql_result = $sql_result; $this -> sql_num_rows = @mysql_num_rows($this -> sql_result); $this -> sql_num_cols = @mysql_num_fields($this -> sql_result); $this -> link = $link; $this -> link_text_patern = $link_text_patern; $this -> cur_page = $cur_page; $this -> link_class = $link_class; $this -> records_per_page = $records_per_page; $this -> total_pages = ceil($this -> sql_num_rows / $this -> records_per_page); $this -> val_min_de_afisat = 0; $this -> val_man_de_afisat = 0; } function show_pagination() { if ($this -> total_pages > $this -> cur_page) { $this -> val_min_de_afisat = $this -> cur_page - ($this -> cur_page % 10); $this -> val_max_de_afisat = $this -> val_min_de_afisat + 10; if ($this -> cur_page > 9) echo ("<a href=\"" . $this -> link . ($this -> val_min_de_afisat-1) . "\" class='".$this -> link_class."'> << </a>\n"); for ($i = $this -> val_min_de_afisat; $i < min($this -> val_max_de_afisat, $this -> total_pages); $i++) { if ($this -> cur_page < $i) printf ("<a href=\"" . $this -> link . ($i) . "\" class='".$this -> link_class."'>" . $this -> link_text_patern . "</a>\n", $i+1); if ($this -> cur_page == $i) printf ("<span class='current'>". $this -> link_text_patern . "</span> \n", $i+1); if ($this -> cur_page > $i) printf ("<a href=\"" . $this -> link . ($i) . "\" class='".$this -> link_class."'>" . $this -> link_text_patern . "</a>\n", $i+1); } if ($this -> val_max_de_afisat < $this -> total_pages) printf ("<a href=\"" . $this -> link . ($i) . "\" class='".$this -> link_class."'> >> </a>\n", $i+1); } } } //**************************************************************** Redirect URl ******************************* function _url($url){ echo("<script language ='JavaScript'>\n"); echo("document.location ='$url';\n"); echo("</script>\n"); } //******************************************************************************* Alert Message ******************************* function _alert($msg){ echo("<script language ='JavaScript'>\n"); echo("alert('$msg');\n"); echo("</script>\n"); } ?>

                    var_dump($record_set), not var_dump($recordset).

                      Write a Reply...