s_ainley87 Posted March 14, 2008 Share Posted March 14, 2008 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? Quote Link to comment Share on other sites More sharing options...
accident Posted March 14, 2008 Share Posted March 14, 2008 Most likely your query is failing Try running the query in mysql and see if you get an error Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 14, 2008 Share Posted March 14, 2008 At the end? AND product.product_id = '$pid' Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 14, 2008 Share Posted March 14, 2008 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 Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 14, 2008 Author Share Posted March 14, 2008 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. Quote Link to comment Share on other sites More sharing options...
accident Posted March 14, 2008 Share Posted March 14, 2008 you missed the { at if (mysql_num_rows($result) == 1) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 14, 2008 Share Posted March 14, 2008 You probably want an opening "{" after this line: <?php if (mysql_num_rows($result) == 1) ?> BTW, what was causing the original error? Ken Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 14, 2008 Author Share Posted March 14, 2008 becuase i am crosslinking a query with two tables i hadnt declared the fields properly. Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 14, 2008 Author Share Posted March 14, 2008 I have tried your above suggestion and it is still not working i am goig mad! :'( Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 14, 2008 Share Posted March 14, 2008 What is the code now with all of your changes up to this point? Quote Link to comment Share on other sites More sharing options...
accident Posted March 14, 2008 Share Posted March 14, 2008 well the query in your previous post is exactly same as first post... you need to fix it Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 14, 2008 Author Share Posted March 14, 2008 Sorry that was unclear i have changed the query on my local host but only changed the code to show line 'whatever' on the forum, sorry for the confusion. Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 14, 2008 Author Share Posted March 14, 2008 Solved i hadnt closed a previous if how stupid do i look ??? Any way thanks for your suggestions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.