Devilboy97 Posted September 24, 2011 Share Posted September 24, 2011 Hi, I have a problem with the example two:Coffee. I have downloaded the script from Larry's site and installed in my server: http://www.gbilling.com. When i click the link cart or wishlist,an error appear: An error occurred in script'/home/gbilling/public_html/gmuar02/wishlist.php' on line 80:mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given...... The Cart .php is like this: <?php // This file manages the shopping cart. // This script is begun in Chapter 9. // Require the configuration before any PHP code: require ('./includes/config.inc.php'); // Check for, or create, a user session: if (isset($_COOKIE['SESSION'])) { $uid = $_COOKIE['SESSION']; } else { $uid = md5(uniqid('biped',true)); } // Send the cookie: setcookie('SESSION', $uid, time()+(60*60*24*30)); // Include the header file: $page_title = 'Coffee - Your Shopping Cart'; include ('./includes/header.html'); // Require the database connection: require (MYSQL); // Need the utility functions: include ('./includes/product_functions.inc.php'); // If there's a SKU value in the URL, break it down into its parts: if (isset($_GET['sku'])) { list($sp_type, $pid) = parse_sku($_GET['sku']); } if (isset ($pid, $sp_type, $_GET['action']) && ($_GET['action'] == 'add') ) { // Add a new product to the cart: $r = mysqli_query($dbc, "CALL add_to_cart('$uid', '$sp_type', $pid, 1)"); // For debugging purposes: //if (!$r) echo mysqli_error($dbc); } elseif (isset ($sp_type, $pid, $_GET['action']) && ($_GET['action'] == 'remove') ) { // Remove it from the cart. $r = mysqli_query($dbc, "CALL remove_from_cart('$uid', '$sp_type', $pid)"); } elseif (isset ($sp_type, $pid, $_GET['action'], $_GET['qty']) && ($_GET['action'] == 'move') ) { // Move it to the cart. // Determine the quantity: $qty = (filter_var($_GET['qty'], FILTER_VALIDATE_INT, array('min_range' => 1))) ? $_GET['qty'] : 1; // Add it to the cart: $r = mysqli_query($dbc, "CALL add_to_cart('$uid', '$sp_type', $pid, $qty)"); // Remove it from the wish list: $r = mysqli_query($dbc, "CALL remove_from_wish_list('$uid', '$sp_type', $pid)"); } elseif (isset($_POST['quantity'])) { // Update quantities in the cart. // Loop through each item: foreach ($_POST['quantity'] as $sku => $qty) { // Parse the SKU: list($sp_type, $pid) = parse_sku($sku); if (isset($sp_type, $pid)) { // Determine the quantity: $qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0)) !== false) ? $qty : 1; // Update the quantity in the cart: $r = mysqli_query($dbc, "CALL update_cart('$uid', '$sp_type', $pid, $qty)"); } } // End of FOREACH loop. }// End of main IF. // Get the cart contents: $r = mysqli_query($dbc, "CALL get_shopping_cart_contents('$uid')"); if (mysqli_num_rows($r) >= 1) { // Products to show! include ('./views/cart.html'); } else { // Empty cart! include ('./views/emptycart.html'); } // Finish the page: include ('./includes/footer.html'); ?> Wishlist.php <?php // This file manages the wish list. // This script is begun in Chapter 9. // Require the configuration before any PHP code: require ('./includes/config.inc.php'); // Check for, or create, a user session: if (isset($_COOKIE['SESSION'])) { $uid = $_COOKIE['SESSION']; } else { $uid = md5(uniqid('biped',true)); } // Send the cookie: setcookie('SESSION', $uid, time()+(60*60*24*30)); // Include the header file: $page_title = 'Coffee - Your Wish List'; include ('./includes/header.html'); // Require the database connection: require (MYSQL); // Need the utility functions: include ('./includes/product_functions.inc.php'); // If there's a SKU value in the URL, break it down into its parts: if (isset($_GET['sku'])) { list($sp_type, $pid) = parse_sku($_GET['sku']); } if (isset ($sp_type, $pid, $_GET['action']) && ($_GET['action'] == 'remove') ) { // Remove it from the wish list. $r = mysqli_query($dbc, "CALL remove_from_wish_list('$uid', '$sp_type', $pid)"); } elseif (isset ($sp_type, $pid, $_GET['action'], $_GET['qty']) && ($_GET['action'] == 'move') ) { // Move it to the wish list. // Determine the quantity: $qty = (filter_var($_GET['qty'], FILTER_VALIDATE_INT, array('min_range' => 1))) ? $_GET['qty'] : 1; // Add it to the wish list: $r = mysqli_query($dbc, "CALL add_to_wish_list('$uid', '$sp_type', $pid, $qty)"); // For debugging purposes: //if (!$r) echo mysqli_error($dbc); // Remove it from the cart: $r = mysqli_query($dbc, "CALL remove_from_cart('$uid', '$sp_type', $pid)"); // For debugging purposes: //if (!$r) echo mysqli_error($dbc); } elseif (isset($_POST['quantity'])) { // Update quantities in the wish list. // Loop through each item: foreach ($_POST['quantity'] as $sku => $qty) { // Parse the SKU: list($sp_type, $pid) = parse_sku($sku); if (isset($sp_type, $pid)) { // Determine the quantity: $qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0)) !== false) ? $qty : 1; // Update the quantity in the wish list: $r = mysqli_query($dbc, "CALL update_wish_list('$uid', '$sp_type', $pid, $qty)"); } } // End of FOREACH loop. }// End of main IF. // Get the wish list contents: $r = mysqli_query($dbc, "CALL get_wish_list_contents('$uid')"); if (mysqli_num_rows($r) > 0) { // Products to show! include ('./views/wishlist.html'); } else { // Empty cart! include ('./views/emptylist.html'); } // Finish the page: include ('./includes/footer.html'); ?> Or Is the procedure problem? I cannot store the Procedure in my database. #1304 - PROCEDURE select_categories already exists ... Can anyone help me??Thank you very much!!!! Link to comment Share on other sites More sharing options...
Larry Posted September 26, 2011 Share Posted September 26, 2011 The problem is your stored procedure call isn't working. You say you cannot store the procedure in your database. If so, then you shouldn't be attempting to call it. On the other hand, that error you posted suggests the procedure does already exist. Link to comment Share on other sites More sharing options...
AndrewT Posted September 27, 2011 Share Posted September 27, 2011 What you need to do before trying to fix your Stored Procedure and re-upload it is run this query: DROP PROCEDURE IF EXISTS select_categories; You can replace "select_categories" with any procedure name. To be specific, that code needs to be ran on the database that you have all your tables and stored procedures on. You can do this in phpMyAdmin simply by selecting the database on the left side, then hitting the "SQL" tab and running the query. There are other ways as well, but that is how I do it. That query will destroy the procedure from your database, allowing you to fix any code in it and re-create the procedure. Hope this helps! The first time I got that error, it was because the user I was using in mysql.inc.php to run the stored procedures didn't have EXECUTE permission on the database. You may have that permission, but it is something to check just to make sure. Link to comment Share on other sites More sharing options...
Devilboy97 Posted October 1, 2011 Author Share Posted October 1, 2011 Thank you very much,Larry & Andrew,it work correctly.But i meet another problem.When i go to my admin panel:http://www.gbilling.com/admin,it will appear a SSL error.How to disable the SSL? Link to comment Share on other sites More sharing options...
Larry Posted October 3, 2011 Share Posted October 3, 2011 I see a 404 error for that link. Link to comment Share on other sites More sharing options...
Frank Posted October 28, 2011 Share Posted October 28, 2011 Thank you very much,Larry & Andrew,it work correctly.But i meet another problem.When i go to my admin panel:http://www.gbilling.com/admin,it will appear a SSL error.How to disable the SSL? Check your .htaccess file. Link to comment Share on other sites More sharing options...
Todd.M Posted October 29, 2011 Share Posted October 29, 2011 Just a question so I can understand better (this my just show off my Newbie status:), In the cart.php you have: if (mysqli_num_rows($r) >= 1) { // Products to show! In the wishlist.php you have: if (mysqli_num_rows($r) > 0) { // Products to show! NOTE: (mysqli_num_rows($r) > 0) in the Product show line? Wouldn't it be a more correct statement if written with '>= 1'? Link to comment Share on other sites More sharing options...
Larry Posted October 29, 2011 Share Posted October 29, 2011 It wouldn't be more correct one way or the other. Both mean the same, although I should have been more consistent. Link to comment Share on other sites More sharing options...
Recommended Posts