Makis77 Posted August 31, 2007 Share Posted August 31, 2007 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! Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 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. Quote Link to comment Share on other sites More sharing options...
Makis77 Posted August 31, 2007 Author Share Posted August 31, 2007 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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 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. Quote Link to comment Share on other sites More sharing options...
Makis77 Posted August 31, 2007 Author Share Posted August 31, 2007 hm.. sorry for being such a newbie but can u paste the code with the echo inside? ps: i learn very quickly, i just need some help the 1st times :0 thanx so much! Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 <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. Quote Link to comment Share on other sites More sharing options...
Makis77 Posted September 1, 2007 Author Share Posted September 1, 2007 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... Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 1, 2007 Share Posted September 1, 2007 When you get a variable from a form use $id = $_POST['id']; when the field is name="id". If it's in the URL use $id = $_GET['id']; when your url has ?id=x Quote Link to comment Share on other sites More sharing options...
Makis77 Posted September 1, 2007 Author Share Posted September 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 1, 2007 Share Posted September 1, 2007 If the action of your form is GET, then yes. If it's post use $_POST. Quote Link to comment Share on other sites More sharing options...
Makis77 Posted September 1, 2007 Author Share Posted September 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 1, 2007 Share Posted September 1, 2007 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); Quote Link to comment Share on other sites More sharing options...
Makis77 Posted September 1, 2007 Author Share Posted September 1, 2007 hahhahahaha well i m not geek, yet 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 1, 2007 Share Posted September 1, 2007 Well, read it. What does it say? Look at the query, and look at what is missing. Try a little more at least before asking for help. Quote Link to comment Share on other sites More sharing options...
Makis77 Posted September 1, 2007 Author Share Posted September 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 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) ){ ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.