Jump to content

mysql_num_rows(): supplied argument is not a valid MySQL result resource


amin1982

Recommended Posts

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.
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 "*"

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.