We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,672 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

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

6
Contributors
7
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
9
Views
emidevil
Newbie Poster
3 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
Skill Endorsements: 0

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

vaultdweller123
Posting Pro
574 posts since Sep 2009
Reputation Points: 47
Solved Threads: 81
Skill Endorsements: 2

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....

emidevil
Newbie Poster
3 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

vaultdweller123
Posting Pro
574 posts since Sep 2009
Reputation Points: 47
Solved Threads: 81
Skill Endorsements: 2

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;
veedeoo
Master Poster
735 posts since Oct 2011
Reputation Points: 298
Solved Threads: 129
Skill Endorsements: 13

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

Karthik_pranas
Posting Pro
571 posts since Feb 2011
Reputation Points: 96
Solved Threads: 101
Skill Endorsements: 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.

cossay
Junior Poster
139 posts since Nov 2010
Reputation Points: 17
Solved Threads: 24
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0778 seconds using 2.74MB