MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 19th, 2005, 02:51 PM
J3F J3F is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 17 J3F User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 20 m 46 sec
Reputation Power: 0
Smile mysql_num_rows():

I'm getting a strange error all over this site I'm working on and being a newb to php/sql I'm struggling with it...

Here is the error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/stric9/drunkster-www/lushspace/functions.php on line 20

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/stric9/drunkster-www/lushspace/functions.php on line 28

It's all through the site though...

Here is the code that is producing it:
Code:
<?
$conn_id;
$sql_res;
$sql_res2;
$sql_query;

$HTTP_REFERER=$_SERVER["HTTP_REFERER"];
$REQUEST_METHOD=$_SERVER["REQUEST_METHOD"];

function sql_connect(){
global $conn_id,$sql_host,$sql_user,$sql_pass,$sql_db;
$conn_id=mysql_connect($sql_host,$sql_user,$sql_pa  ss);
mysql_select_db($sql_db);
}

function sql_execute($sql_query,$wtr){
global $conn_id;
$sql_res=mysql_query($sql_query,$conn_id);
if($wtr=='get'){
if(mysql_num_rows($sql_res)){
return mysql_fetch_object($sql_res);
}
else {
return '';
}
}
elseif($wtr=='num'){
return mysql_num_rows($sql_res);
}
elseif($wtr=='res'){
return $sql_res;
}
}


I'd be realy appreciative if someone could help.. Thanks in advance.

Reply With Quote
  #2  
Old September 19th, 2005, 05:13 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Something's wrong with your query -- use mysql_error() to get the db's error message for more specific information.
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
  #3  
Old September 20th, 2005, 08:27 AM
J3F J3F is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 17 J3F User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 20 m 46 sec
Reputation Power: 0
It actually hurts I'm so confuesd.

Quote:
Originally Posted by Madpawn
Something's wrong with your query -- use mysql_error() to get the db's error message for more specific information.


And then there was:
A fatal MySQL error occured.
Query:
Error: (1065) Query was empty

from code:
Code:
<?
$conn_id;
$sql_res;
$sql_res2;
$sql_query;

$HTTP_REFERER=$_SERVER["HTTP_REFERER"];
$REQUEST_METHOD=$_SERVER["REQUEST_METHOD"];
$result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

function sql_connect(){
global $conn_id,$sql_host,$sql_user,$sql_pass,$sql_db;
$conn_id=mysql_connect($sql_host,$sql_user,$sql_pa  ss);
mysql_select_db($sql_db);
}

function sql_execute($sql_query,$wtr){
global $conn_id;
$sql_res=mysql_query($sql_query,$conn_id);
if($wtr=='get'){
if(mysql_num_rows($sql_res)){
return mysql_fetch_object($sql_res);
}
else {
return '';
}
}
elseif($wtr=='num'){
return mysql_num_rows($sql_res);
}
elseif($wtr=='res'){
return $sql_res;
}
}
function sql_rows($id,$table){
global $conn_id;
$query="select $id from $table";
$result=mysql_query($query,$conn_id);
$number=mysql_num_rows($result);
return $number;
}



Reply With Quote
  #4  
Old September 20th, 2005, 08:30 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
You have two variables, $sql_query and $query, and I don't see where either are being set.

Reply With Quote
  #5  
Old September 20th, 2005, 09:48 AM
J3F J3F is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 17 J3F User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 20 m 46 sec
Reputation Power: 0
Well it's not the cleanest thing I've seen but said variables are defined.

Code:
<?
$conn_id;
$sql_res;
$sql_res2;
$sql_query;

$HTTP_REFERER=$_SERVER["HTTP_REFERER"];
$REQUEST_METHOD=$_SERVER["REQUEST_METHOD"];
$result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

function sql_connect(){
global $conn_id,$sql_host,$sql_user,$sql_pass,$sql_db;
$conn_id=mysql_connect($sql_host,$sql_user,$sql_pa  ss);
mysql_select_db($sql_db);
}

function sql_execute($sql_query,$wtr){
global $conn_id;
$sql_res=mysql_query($sql_query,$conn_id);
if($wtr=='get'){
if(mysql_num_rows($sql_res)){
return mysql_fetch_object($sql_res);
}
else {
return '';
}
}
elseif($wtr=='num'){
return mysql_num_rows($sql_res);
}
elseif($wtr=='res'){
return $sql_res;
}
}
function sql_rows($id,$table){
global $conn_id;
$query="select $id from $table";
$result=mysql_query($query,$conn_id);
$number=mysql_num_rows($result);
return $number;
}

function sql_close(){
global $conn_id;
mysql_close($conn_id);
}
function h_banners()	{
global $cookie_url,$main_url;
	
	$sql="select * from banners where b_blk='N' and b_typ='H' and b_exp='N'";
	$res=mysql_query($sql);
	$dis=array();
	$dis_id=array();
	$num=mysql_num_rows($res);
	if(mysql_num_rows($res))	{
		while($row=mysql_fetch_object($res))	{
			$tmp=explode(".",$row->b_img);
			$tmp_count=count($tmp);
			$ext=strtolower($tmp[$tmp_count-1]);
			if($ext=="swf")	{
				$img_s="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='420' height='60'>
  						<param name='movie' value='".$main_url."/".$row->b_img."'>
						<param name='quality' value='high'>
						<embed src='".$main_url."/".$row->b_img."' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='420' height='60'></embed></object>";
			}	else	$img_s="<img src='".$main_url."/".$row->b_img."' border='0' width='420' height='60' alt='".stripslashes($row->b_desc)."' ismap>";
			$dis[]="<A href='".$main_url."/banners/index.php?url=".$row->b_url."&seid=".$row->b_id."&sess=set' target='_blank'>".$img_s."</a>";
			$dis_id[]=$row->b_id;
		}
		$tak=rand(0,$num);
		$sql_query="select * from banners where b_id='$dis_id[$tak]'";
		$num=sql_execute($sql_query,'num');

Reply With Quote
  #6  
Old September 20th, 2005, 10:09 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Are you saying you've fixed the problem, or that there shouldn't be a problem?

Reply With Quote
  #7  
Old September 20th, 2005, 12:33 PM
J3F J3F is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 17 J3F User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 20 m 46 sec
Reputation Power: 0
It's not fixed unfortunatly. I was just showing the lines that defined the variables for MadCowDzz. I added the mysql_query($query) or die line but it just reports that the query is empty..

Reply With Quote
  #8  
Old September 20th, 2005, 12:35 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
The problem's coming from your $query variable -- where's it being set?

Reply With Quote
  #9  
Old September 20th, 2005, 12:42 PM
J3F J3F is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 17 J3F User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 20 m 46 sec
Reputation Power: 0
line 37? ----> $query="select $id from $table";
line 126? ----> $sql_query="select * from banners where b_id='$dis_id[$tak]'";

I sure hope thats what you mean. I'm studying as I go here.

Reply With Quote
  #10  
Old September 20th, 2005, 01:07 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I don't see where your sql_rows() function is being called.
Line 37 is actually declared in a function which is not called.

When your script executes, the line: $result = mysql_query($query) or [...] is being hit first. This is why your query is empty.

In reality, I'm not sure all those functions are truly necessary.

At least for testing purposes: above your mysql_query() call, try placing something like $query = "SELECT * FROM some_table";
Comments on this post
J3F agrees: Very well done.

Reply With Quote
  #11  
Old September 20th, 2005, 01:26 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Even if you call that function, it's returning a query's results, not the query string (if that's even the query you want to run). The $query inside that function is not available to the rest of the script.
Comments on this post
MadCowDzz agrees: I failed to mention these points.
J3F agrees: very well done

Reply With Quote
  #12  
Old September 22nd, 2005, 07:40 AM
J3F J3F is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 17 J3F User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 20 m 46 sec
Reputation Power: 0
Thanks folks, I got alot of work ahead of me.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql_num_rows():


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway