Jump to content

mysql_num_rows error


s_ainley87

Recommended Posts

Hello Everybody,

 

I am getting the following error when i try to display a page,

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\JetStore\view_print.php on line 15

 

Below is my code

<?php 
// This page displays the details for a particular product.

$problem = FALSE; // Assume no problem.

if (isset($_GET['pid'])) { // Make sure there's a product ID.

$pid = (int) $_GET['pid'];

require_once ('include/mysql_connect.php'); // Connect to the database.

$query = "SELECT category_id, category_name, product_name, product_desc, image_name FROM category, product WHERE category.category_id = product.category_id AND product.product_id = $pid";
$result = mysql_query ($query, $dbc);

if (mysql_num_rows($result) == 1)#<-----LINE 15 { // Good to go!

	// Fetch the information.
	$row = mysql_fetch_array ($result); 

	// Start the HTML page.
	$page_title = $row['product_name'];


	// Display a header.
	echo "<div align=\"center\">
<b>{$row['product_name']}</b> by 
{$row['name']}

<br />\${$row['product_price']} 
<a href=\"add_cart.php?pid=$pid\">Add to Cart</a>
</div><br />";

	// Get the image information and display the image.
	if ($image = @getimagesize ("uploads/{$row['image_name']}")) {
		echo "<div align=\"center\"><img src=\"show_image.php?image={$row['image_name']}\" $image[3] alt=\"{$row['product_name']}\" />";	
	} else {
		echo "<div align=\"center\">No image available."; 
	}
	echo "<br />{$row['description']}</div>";

} else { // No record returned from the database.
	$problem = TRUE;
}

mysql_close($dbc); // Close the database connection.

} else { // No product ID.
$problem = TRUE;
}

if ($problem) { // Show an error message.
$page_title = 'Error';
echo '<div align="center">This page has been accessed in error!</div>';
}

 

I personally cannot see the problem maybe i am being slow though?

Link to comment
Share on other sites

Change

<?php
$result = mysql_query ($query, $dbc);
?>

to

<?php
$result = mysql_query ($query, $dbc) or die("Problem with the query: $query<br>" . mysql_error());
?>

 

The resulting output should tell you where the problem lies.

 

Ken

Link to comment
Share on other sites

ok the query is fine i now get this error message,

Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\JetStore\view_print.php on line 49

<?php 
// This page displays the details for a particular product.

$problem = FALSE; // Assume no problem.

if (isset($_GET['pid'])) { // Make sure there's a product ID.

$pid = (int) $_GET['pid'];

require_once ('include/mysql_connect.php'); // Connect to the database.

$query = "SELECT category_id, category_name, product_name, product_desc, image_name FROM category, product WHERE category.category_id = product.category_id AND product.product_id = $pid";
$result = mysql_query ($query, $dbc);

if (mysql_num_rows($result) == 1)#<-----LINE 15 { // Good to go!

	// Fetch the information.
	$row = mysql_fetch_array ($result); 

	// Start the HTML page.
	$page_title = $row['product_name'];


	// Display a header.
	echo "<div align=\"center\">
<b>{$row['product_name']}</b> by 
{$row['name']}

<br />\${$row['product_price']} 
<a href=\"add_cart.php?pid=$pid\">Add to Cart</a>
</div><br />";

	// Get the image information and display the image.
	if ($image = @getimagesize ("uploads/{$row['image_name']}")) {
		echo "<div align=\"center\"><img src=\"show_image.php?image={$row['image_name']}\" $image[3] alt=\"{$row['product_name']}\" />";	
	} else {
		echo "<div align=\"center\">No image available."; 
	}
	echo "<br />{$row['description']}</div>";

} else { // No record returned from the database.
	$problem = TRUE;
}

mysql_close($dbc); // Close the database connection.

} else { // No product ID. #LINE 49 IS HERE
$problem = TRUE;
}

if ($problem) { // Show an error message.
$page_title = 'Error';
echo '<div align="center">This page has been accessed in error!</div>';
}

I have marked the line.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.