Supplied Argument Is Not A Valid Mysql Result Resource

liunx

Guest
Hope someone can help because my eyes at this point are bleeding...<br /><br />I've been working on this code for a while and had converted a page with some queries but each one I would get this: <br /><br />Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/moviema/public_html/reviews/backup/read.php on line xx<br /><br />So, I figured I made a big mistake somewhere along the line so I started over and decided to go step by step for each place I needed the database info. The first one (in the head section) gave me the same warning. It has something to do with the $id = $_GET['id']; part as I had created a page to make sure the data was actually there. Taking out the get part and just grabbing the data, it displayed fine, put it back in, and that warning was there.<br /><br />Here's a link to the test page I made just displaying the fields (I only have one row):<br /><a href="http://www.moviemansguide.com/reviewtest2.php" target="_blank">http://www.moviemansguide.com/reviewtest2.php</a><br /><br />and here's the main page I'm working on (the other sections will be coded later, but I wanted to solve this problem first):<br /><a href="http://www.moviemansguide.com/reviews/backup/read.php?id=runningscared" target="_blank">http://www.moviemansguide.com/reviews/back...d=runningscared</a><br /><br />and the particular php code giving me troubles:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br />$dbcnx = @mysql_connect('localhost', 'username', 'password');<br />if (!$dbcnx) {<br />  exit('<p>Unable to connect to the ' .<br />      'database server at this time.</p>');<br />}<br /><br />if (!@mysql_select_db('database')) {<br />  exit('<p>Unable to locate the review ' .<br />      'database at this time.</p>');<br />}<br /><br />$id = $_GET['id'];<br /><br />$titleinfo = @mysql_query('SELECT title, year, edition FROM dvd_reviews WHERE id='.$id.'');<br /><br />while ($info = mysql_fetch_array($titleinfo)) {<br />    $title = $info['title'];<br />    $year = $info['year'];<br />    $edition = $info['edition'];<br />    echo "<title>Movieman's Guide to the Movies >> DVD Review >> $title ($year) - $edition</title>";<br />}<br />?><!--c2--></div><!--ec2--><br /><br />The line the error occurs at the "while" function.<br /><br />I've looked at that code and cannot figure out why I'm getting this warning so I'm missing something (and probably obvious). I'd appreciate any help at all.<!--content-->
Update:<br /><br />I've added an error code and got this now:<br /><br />Error retrieving information from database.<br />Error: Unknown column 'runningscared' in 'where clause'<br /><br />Now, I know it exists so I'm still confused. I am going to try one more thing though...<!--content-->
I know very little about MySQL, but I think your problem lies here:<br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->$titleinfo = @mysql_query(<b>'</b>SELECT title, year, edition FROM dvd_reviews WHERE id=<b>'</b>.$id.<b>'</b><b>'</b>);<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Syntactically, you have to watch your quoting, because the 'interpreter' cannot distinguish between an open quote and an close quote, so all the 'interpreter' sees in your code is this:<br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->$titleinfo = @mysql_query(<b>'</b>SELECT title, year, edition FROM dvd_reviews WHERE id=<b>'</b><i><<stuff that it doesn't understand because it is outside the quotes>></i>)<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Try this:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$titleinfo = @mysql_query("SELECT title, year, edition FROM dvd_reviews WHERE id='.$id.'");<!--c2--></div><!--ec2--><!--content-->
<!--quoteo(post=182732:date=Jun 16 2006, 01:34 AM:name=Steve Scrimpshire)--><div class='quotetop'>QUOTE(Steve Scrimpshire @ Jun 16 2006, 01:34 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=182732"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->I know very little about MySQL, but I think your problem lies here:<br />Syntactically, you have to watch your quoting, because the 'interpreter' cannot distinguish between an open quote and an close quote, so all the 'interpreter' sees in your code is this:<br />Try this:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$titleinfo = @mysql_query("SELECT title, year, edition FROM dvd_reviews WHERE id='.$id.'");<!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Yeah, I had tried that and while the warning is gone, what I have in the echo, does not display (and when viewing the code through IE, there's nothing in the title area... I've done this before with an old database and it worked fine so I don't know why I'm having such problems now.<br /><br />I have updated the code with those double quotes, I figure it's some kind of progress.<br /><br /><br />EDIT: Problem fixed. With those double quotes, I also removed the periods from either side of the $id, and now it works. So thanks Steve <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
 
Back
Top