amin1982 Posted November 16, 2006 Share Posted November 16, 2006 Hey guys,I'm having soem truble with the code below. I'm repeatedly receiving the common [b]mysql_num_rows(): supplied argument is not a valid MySQL result resource[/b] error. I've tried one or two things including editing the code but 2 hours later this is still killing.anyhelp would be appreciated.[code]<?php $problem = FALSE; // Assume no problem.if (isset($_GET['book_isbn'])) { // book ID $book_isbn= (int) $_GET['book_isbn']; require_once ('./includes/mysql_connect.php'); // //require_once ('./includes/config.inc.php'); $sql = mysql_query ("SELECT book_title, book_author, book_year, book_price, book_description, book_image, book_status AS book_title, book_author, book_year, book_price, book_description, book_image, book_status FROM books WHERE book_isbn = $book_isbn")or die(mysql_error()); $result = mysql_query ($sql, $dbc); if (mysql_num_rows($result)) { // ERROR IS HERE LINE 21.... // Fetch the information. $row = mysql_fetch_array ($result, MYSQLI_ASSOC); // Display a header. echo "<div align=\"center\"> <b>{$row['book_title']}</b> by {$row['book_author']} <br />{$row['book_isbn']} <br />\${$row['book_price']} <a href=\"add_cart.php?book_isbn=$book_isbn\">Add to Cart</a> </div><br />"; // Get the image information and display the image. if ($image = @getimagesize ("../../uploads/{$row['book_image']}")) { echo "<div align=\"center\"><img src=\"show_image.php?image={$row['book_image']}\" $image[3] alt=\"{$row['book_title']}\" />"; } else { echo "<div align=\"center\">No image available."; } echo "<br />{$row['book_description']}</div>"; } else { $problem = TRUE; } mysql_close($dbc); } else { // No print ID. $problem = TRUE;}if ($problem) { echo '<div align="left">Error!!</div>';}?>[/code]The error is on line 22 and is pointed out above.Thanks again. Link to comment https://forums.phpfreaks.com/topic/27408-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
Psycho Posted November 16, 2006 Share Posted November 16, 2006 Look at the two lines previous to the error:[code]<?php $sql = mysql_query ("SELECT book_title, book_author, .... ")or die(mysql_error()); $result = mysql_query ($sql, $dbc);?>[/code]You are running [b]mysql_query[/b] twice! Change to this:[code]<?php $sql = "SELECT book_title, book_author, book_year, book_price, book_description, book_image, book_status AS book_title, book_author, book_year, book_price, book_description, book_image, book_status FROM books WHERE book_isbn = $book_isbn"; $result = mysql_query ($sql, $dbc);?>[/code]By the way, if you are grabing that many fields it would probably be more efficient to just use "*" Link to comment https://forums.phpfreaks.com/topic/27408-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-125373 Share on other sites More sharing options...
amin1982 Posted November 16, 2006 Author Share Posted November 16, 2006 that worked a treat!!thanks alot!! Link to comment https://forums.phpfreaks.com/topic/27408-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-125386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.