|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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" |
|
#3
|
|||
|
|||
|
It actually hurts I'm so confuesd.
Quote:
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;
}
![]() |
|
#4
|
||||
|
||||
|
You have two variables, $sql_query and $query, and I don't see where either are being set.
|
|
#5
|
|||
|
|||
|
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');
|
|
#6
|
|||
|
|||
|
Are you saying you've fixed the problem, or that there shouldn't be a problem?
|
|
#7
|
|||
|
|||
|
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..
|
|
#8
|
|||
|
|||
|
The problem's coming from your $query variable -- where's it being set?
|
|
#9
|
|||
|
|||
|
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. |
|
#10
|
||||
|
||||
|
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"; |
|
#11
|
|||
|
|||
|
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.
|
|
#12
|
|||
|
|||
|
Thanks folks, I got alot of work ahead of me.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > mysql_num_rows(): |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|