1.11M Members

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given PHP

 
0
 

I really dunno wats wrong here. the firts query works but the second does not . please help...

There a these connected files:

save.php

<?php
include_once("classes/jewelry/item.class.php");

$inum = $_POST['ItemNo'];
$i=new item();
	$i->ItemNo = $inum;
	$i->ItemName= $_POST['ItemName'];
	$i->CapitalPrice=$_POST['CapitalPrice'];
	$i->SalePrice=$_POST['SalePrice'];
	$i->Category=$_POST['Category'];
	$i->Description=$_POST['Description'];
$i->save();
include_once("classes/jewelry/stock.class.php");
$j=new stock();
	$j->ItemNo = $inum;
	$j->NumStored= $_POST['Nload'];
	$j->NumSold= 0;
$j->save();

header("Location:?unit=inventory&go=home&task=inventory_index");
exit(); 
?>

@item.class.php

class stock extends Core {
<some declaration of attributes>....
	function save(){
		$sql="INSERT INTO $this->coreTable(ItemNo,NumStored,NumSold)".
				  " VALUES('$this->ItemNo','$this->NumStored','$this->NumSold')";					  	
		$this->Execute($sql);	
	   return $this->sqlOK;  	   	
	}
}

and @clas_core.php

class Core {
<some declaration of attributes>....
	function Execute($query) {
		$this->result = mysql_query($query) or die('Error, query failed!!!');
		$this->num_rows = mysql_num_rows( $this->result );
	}
}

Well as for the firstquery concerning item.it is successfully inserted into the database but when it comes to the stock. no instance is inserted and it gives a Warning"
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\jewelry_system\classes\class_core.php on line 19
Error, query failed!!!

I dunno what wrong. am i violating somerule. coz thefirst query which exactlyis the same as second is working perfectly fine T_T

 
1
 

In your @item.class.php file I would write

echo $sql;

And see what the query actually is. It sounds like there's something missing in the query or it's not vein written correctly.

 
0
 

show the whole code of clas_core.ph, the error is on line 19

 
0
 

show the whole code of clas_core.ph, the error is on line 19

class Core {
	public $coreTable;
	public $result;
	public $num_rows;
	
	var $sql;
	var $count;
	var $affected;
	var $conn;
	var $lasterror;
	var $lastid;
	var $sqlOK;	
	
	function Execute($query) {
		$this->result = mysql_query($query) or die('Error, query failed!!!');   
		$this->num_rows = mysql_num_rows( $this->result ); //this is line 19.
	}

	
	function Core(&$conn=NULL) {
		$this->sql='';
		$this->result='';
		$this->count=-1;
		$this->affected=-1;
		$this->coreTable = '';
	}
...

well i ddnt post the whole and at first didnt post this because it works perfectly on the first part. on the item part.it updated the sql. but at the stock part it doesnt....

 
0
 

i'm sure that error means there is wrong with your query, have you tried checking if your query really works? try running your query on phpmyadmin's SQL tab

 
0
 

UPDATED: Please ignore my response below. I think I have a wrong assumption, because I run a test class to see it cycling has effects or not, but unfortunately based on my model it has no bearing at all..

dummy script extracted from a class used for evaluation.

function multi_Mynum(){
       $this->a = ( $this->val1 * $this->val2 * $this->val3 );
	   return "{$this->a}"; 
	 }

I might be wrong on this one. try cycling this

$this->num_rows = mysql_num_rows( $this->result );

I think I must have encountered a similar problem like this before, but not very sure when and which script?. I hope it would not hurt to try.

To cycle it,it would be something like this

$res = mysql_num_rows( $this->result ); ## now res is defined and isolated
$this->num_rows = $res;
 
0
 

Echo your query as follows

class Core {
    <some declaration of attributes>....
    function Execute($query) {
    echo $query;
    $this->result = mysql_query($query) or die('Error, query failed!!!');
    $this->num_rows = mysql_num_rows( $this->result );
    }
    }

and check the query with phpmyadmin's SQL section

 
0
 

The mysql_num_rows function is used only on queries that return records from mysql database. So you can use it on SELECT queries but you cannot use it on UPDATE, INSERT, and DELETE queries. This is because these queries return booleans no mather what happens.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: