armlocker Posted March 23, 2013 Share Posted March 23, 2013 Hi guys. Finally at the end of Chapter 10. I have a problem with the wishlist.php.The cart.php works fine, and they are nearly the same. When I transfer stuff to the 'Wishlist', I get this error: Parse error: syntax error, unexpected $end in /hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut.co.uk/wishlist.php on line 110 I have been trying to locate the missing parenthesis error from beginning to end for half a day, so I guess its time to ask for help. I've made sure all the single and double quotations are as they should be, so I don't think its that. The script is from downloads. Only the pathways and stored procedures sections are different. <?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.inc.php'); // 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, "SELECT id FROM carts where user_session_id='$uid' AND product_type='$sp_type' AND product_id=$pid"); if (mysqli_num_rows($r) == 1) { // Exists in cart, UPDATE! list($cid) = mysqli_fetch_array($r, MYSQLI_NUM); $r = mysqli_query($dbc, "UPDATE carts SET quantity=quantity+1, date_modified=NOW() WHERE id=$cid"); } else { // Not in cart, INSERT! $r = mysqli_query($dbc, "INSERT INTO carts (user_session_id, product_type, product_id, quantity) VALUES ('$uid', '$sp_type', $pid, 1)"); } // For debugging purposes: if (!$r) echo mysqli_error($dbc); // Remove it from the cart: $r = mysqli_query($dbc, "DELETE FROM carts WHERE user_session_id='$uid' AND product_type='$sp_type' AND product_id=$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: if ($qty > 0) { $r = mysqli_query($dbc, "UPDATE carts SET quantity=$qty, date_modified=NOW() WHERE user_session_id='$uid' AND product_type='$sp_type' AND product_id=$pid"); } elseif ($qty == 0) { $r = mysqli_query($dbc, "DELETE FROM carts WHERE user_session_id='$uid' AND product_type='$sp_type' AND product_id=$pid"); } } // End of FOREACH loop. }// End of main IF. // Get the wish list contents: $r = mysqli_query($dbc, "SELECT CONCAT('O', ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type='other' AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type='other' AND c.user_session_id='$uid' UNION SELECT CONCAT('C', sc.id), c.quantity, gc.category, CONCAT_WS(' - ', s.size, sc.caf_decaf, sc.ground_whole), sc.price, sc.stock, sales.price FROM carts AS c INNER JOIN specific_coffees AS sc ON c.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id LEFT OUTER JOIN sales ON (sales.product_id=sc.id AND sales.product_type='coffee' AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type='coffee' AND c.user_session_id='$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'); ?> Link to comment Share on other sites More sharing options...
margaux Posted March 24, 2013 Share Posted March 24, 2013 Looks like you haven't closed the final elseif clause. Try putting a closing curly bracket on line 87. You probably want to use a text editor which folds your code to make it easier to find these kind of errors. 1 Link to comment Share on other sites More sharing options...
armlocker Posted March 24, 2013 Author Share Posted March 24, 2013 Hail Margaux - you did it! How in wonder did you spot that? I swear I went through the thing matching each and every parenthesis, closing bracket and single and double quotations.... Link to comment Share on other sites More sharing options...
Recommended Posts