Jump to content

Hello!!! i got this mysql_fetch_object(): supplied argument is not a valid MySQL


Makis77

Recommended Posts

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/myspace/public_html/plugins/layouts/cats.php on line 49

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/myspace/public_html/plugins/layouts/cats.php on line 64

 

here is the code, in bold letters its the lines 49 and 64


<table width="100%" border="0" cellspacing="0" cellpadding="3">

<tr>

<td><form action="" method="get">

<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">

<option value="">Select Layout Type</option>

<?

$fetch = mysql_query("SELECT * FROM layout_cats");

while( $row = mysql_fetch_object($fetch) ){

?>

<option value="<? echo ("$url"); ?>index.php?app=layouts&action=cats&id=<?=$row->id?>"><?=$row->name?></option>

<?

}

?>

  </select>

</form></td>

  </tr>

</table>   

<?

$fetch = mysql_query("SELECT * FROM layout_cats WHERE id=$id ORDER BY id DESC");

$cat = mysql_fetch_object($fetch);

$seo_title = $sitename." - ".$cat->name." Layouts";

?>             

<h1><?=$cat->name?> Layouts</h1>

<?

$fetch2 = mysql_query("SELECT * FROM layouts WHERE cat_id=$id AND published='1' ORDER BY id DESC");

while( $row = mysql_fetch_object($fetch2) ){

?> 


 

 

if i put instead of: $id directly the category i need, lets say '1' then it works fine. Only this is a drop down menu from which the user select the category he want to see the result, so if i put '1' then he will always see the category with id=1

 

any help we ll be appreciated!

 

thanx a lot in advance!

 

 

Your query is failing. Change this:

$fetch = mysql_query("SELECT * FROM layout_cats WHERE id=$id ORDER BY id DESC");

 

to:

$fetch = @mysql_query("SELECT * FROM layout_cats WHERE id=$id ORDER BY id DESC") or die(mysql_error());

to see what the error is.

thanx,

i got the following:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id DESC' at line 1

 

mysql ver: 4.1.22-standard

php ver:    4.4.3

 

i tried to remove the order by but still i get the same error

Assuming your $id variable is supposed to be a number, it is either empty, or not a number. It is possible that it contains illegal characters, but I wouldn't think so. Put an "echo $id" line before the query and see what you get.

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><form action="" method="get">
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<option value="">Select Layout Type</option>
<?
$fetch = mysql_query("SELECT * FROM layout_cats");
while( $row = mysql_fetch_object($fetch) ){
?>
<option value="<? echo ("$url"); ?>index.php?app=layouts&action=cats&id=<?=$row->id?>"><?=$row->name?></option>
<?
}
?>
  </select>
</form></td>
  </tr>
</table>    
<?
if (isset($id))
   echo "ID is: " . $id  . "<br>";
else
   echo "ID is empty!<br>";
$fetch = mysql_query("SELECT * FROM layout_cats WHERE id=$id ORDER BY id DESC");

$cat = mysql_fetch_object($fetch);
$seo_title = $sitename." - ".$cat->name." Layouts";
?>              
<h1><?=$cat->name?> Layouts</h1>
<?
$fetch2 = mysql_query("SELECT * FROM layouts WHERE cat_id=$id AND published='1' ORDER BY id DESC");
while( $row = mysql_fetch_object($fetch2) ){
?>  

That should either show the value for id or say it is empty.

i get the following:

 

ID is empty!

 

...

 

maybe that means that the code is not correctly configured since i have the tables with the id's installed,

maybe the drop down menu doesnt work correctly???

 

visit:

 

http://www.myspacerequest.com

 

and select from top menu the 'Layouts' option.

Then select from the box the layout category u want to see and u will get the message.

 

Keep in mind that the sql table from cats has id's inside...

so now i change

 

$fetch = mysql_query("SELECT * FROM layout_cats WHERE id=$id ORDER BY id DESC");

 

to

 

$fetch = mysql_query("SELECT * FROM layout_cats WHERE id=$_GET['id'] ORDER BY id DESC");

 

and

 

$fetch2 = mysql_query("SELECT * FROM layouts WHERE cat_id=$id AND published='1' ORDER BY id DESC");

 

to

 

$fetch2 = mysql_query("SELECT * FROM layouts WHERE cat_id=$_GET['id'] AND published='1' ORDER BY id DESC");

 

urli is like:

 

http://www.myspacerequest.com/index.php?app=layouts&action=cats&id=1

its get alright,

i just did that and i got the following:

 

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/mysite/public_html/plugins/layouts/cats.php on line 44

 

where lne 44 has:

 

$fetch = mysql_query("SELECT * FROM layout_cats WHERE id=$_POST['id'] ORDER BY id DESC");

 

it seems he cant understand this change.

 

 

ps: Thanx a lot :)

Your server is a male? Usually geeks call their computers as females.

 

$sql = "SELECT * FROM layout_cats WHERE id=".$_POST['id']." ORDER BY id DESC";
$fetch = mysql_query($sql) OR die(mysql_error().' Query: '.$sql);

hahhahahaha

 

well i m not geek, yet :P

 

i replaced with

$sql = "SELECT * FROM layout_cats WHERE id=".$_POST['id']." ORDER BY id DESC";
$fetch = mysql_query($sql) OR die(mysql_error().' Query: '.$sql);

 

and now i get:

 

ID is empty!

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id DESC' at line 1 Query: SELECT * FROM layout_cats WHERE id= ORDER BY id DESC

jesirose, as i wrote before i m a completely newbie.

I only have some swl and oracle serious backround.

 

i replaced _POST with _GET

and i got results but stil i get some malfunction

see this:

 

http://www.myspacerequest.com/index.php?app=layouts&action=cats&id=20

Try:

 




<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><form action="" method="get">
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<option value="">Select Layout Type</option>
<?php
$fetch = mysql_query("SELECT * FROM layout_cats");
while( $row = mysql_fetch_array($fetch) ){
?>
<option value="<? echo ("$url"); ?>index.php?app=layouts&action=cats&id=<?=$row->id?>"><?=$row->name?></option>
<?php
}
?>
  </select>
</form></td>
  </tr>
</table>    
<?php
$fetch = mysql_query("SELECT * FROM layout_cats WHERE id=$id ORDER BY id DESC");

$cat = mysql_fetch_array($fetch);
$seo_title = $sitename." - ".$cat->name." Layouts";
?>              
<h1><?=$cat->name?> Layouts</h1>
<?php
$fetch2 = mysql_query("SELECT * FROM layouts WHERE cat_id=$id AND published='1' ORDER BY id DESC");
while( $row = mysql_fetch_array($fetch2) ){
?>  








Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.