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
https://forums.phpfreaks.com/topic/96174-mysql_num_rows-error/
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
https://forums.phpfreaks.com/topic/96174-mysql_num_rows-error/#findComment-492314
Share on other sites

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.