Jump to content
Larry Ullman's Book Forums

armlocker

Members
  • Content Count

    83
  • Joined

  • Last visited

  • Days Won

    1

armlocker last won the day on March 19 2013

armlocker had the most liked content!

Community Reputation

3 Neutral

About armlocker

  • Rank
    Advanced Member
  1. ... woops - my bad ... here's what is now showing after echo $query; =============================================================== QUESTION 1 How many bytes are used to represent the primitive...? Choose the right answer: Resource id #42 4 8 1 correct answer
  2. Hello again Yoda of PHP I have echoed the $sql; under the select query above and now I get the : Notice: Undefined variable: sql in C:\xampp\htdocs\game\index.php on line 16 my database (questions) structure is simple. here are the coloumns questions_record_number question_id question answer option1 option2 option3 option4 subject NOTHING IS WORKING AT THE MOMENT - AND HERES WHATS SHOWING =============================================================== QUESTION 1 How many bytes are used to represent the primitive...? Choose the right answer: Notice: Undefined variable: sql in C:\xampp\htdocs\game\index.php on line 16 2 4 8 1 correct answer ============================================================== I know its something really simple - I just cant figure it out, and is an excellent exercise for getting results from the database, useful in many situations. .... over to you Sir
  3. Hi there, just trying to get some practice in by creating a simple php game - can someone tell me where am I going wrong please: Thanks in advance <?php $con = mysql_connect('localhost', 'root', ''); mysql_select_db("krish"); ?> QUESTION 1<br><br> How many bytes are used to represent the primitive...? <br><br> Choose the right answer:<br><br> <?php $query = mysql_query("SELECT * FROM questions WHERE question_id = 'Q1'"); while ($row = mysql_fetch_assoc($query)) { echo $row['option1'] . '<input type="radio" name="option_1" value="option1"><br>'; echo $row['option2'] . '<input type="radio" name="option_1" value="option2"><br>'; echo $row['option3'] . '<input type="radio" name="option_1" value="option3"><br>'; echo $row['option4'] . '<input type="radio" name="option_1" value="option4"><br>'; } $var = "select from answer questions where answer ='4'"; if (isset($var)) { echo 'correct answer'; } else { echo 'wrong answer'; } ?>
  4. .... you see these parts in the script; they are meant to bring the user back to checkout.php after they press the pay button. <br /><br />'.$checkout_button.'</p>'; and this part: <input type="hidden" name="notify_url" Value="http://www.wolfcut.co.uk/checkout.php" /> I was trying this; to link the checkout button; which didn't work either: <br /><br /><a href="checkout.php"'.$checkout_button.'</a></p>';
  5. Hi HartleySan Yep, I've just spotted that typo too, should be: session_id($cid); the view_cart.php with the added paypal button looks like this - which is not linking to the checkout.php after the customer presses the buy button: echo "\t<tr> <td align=\"left\">{$row['artist']}</td> <td align=\"left\">{$row['print_name']}</td> <td align=\"right\">£{$_SESSION['cart'][$row['print_id']]['price']}</td> <td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['print_id']}]\" value=\"{$_SESSION['cart'][$row['print_id']]['quantity']}\" /></td> <td align=\"right\">£" . number_format ($subtotal, 2) . "</td> </tr>\n"; $string_of_item_names = $string_of_item_names.' <input type="hidden" name="item_name_'.$count.'" Value="'.$row['print_name'].'" >'; # build item name string of all items in the basket $string_of_item_amounts = $string_of_item_amounts.' <input type="hidden" name="amount_'.$count.'" Value="'. number_format ($subtotal, 2).'" >'; # build string of prices for items in basket # use count as a reference to match names with prices in paypal $count++; } // End of the WHILE loop. mysqli_close($con); // Close the database connection. if ($_SESSION['userid']>0) $checkout_button = ('<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <!-- Identify your business so that you can collect the payments. HELP: https://www.paypal.com/us/cgi-bin/webscr?cmd=_pdn_xclick_techview_outside https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HF00TZS We use cart becuase we have our own (third party which is us) --> <input type="hidden" name="business" value="hello@richmond"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <!--- this is where the user comes back to after they finished making the payment ---> <input type="hidden" name="notify_url" Value="http://www.wolfcut.co.uk/checkout.php" /> <!-- Specify details about the item that buyers will purchase. --> '.$string_of_item_names.' '.$string_of_item_amounts.' <input type="hidden" name="currency_code" value="GBP"> <!-- Display the payment button. --> <div align="center"> <input type="image" name="submit" border="0" align="center" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online"> <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" > </div> </form>'); else $checkout_button = '<a href="login.php">You must be logged in to purchase or please sign up.</a>'; // Print the total, close the table, and the form: echo '<tr> <td colspan="4" align="right"><b>Total: </b></td> <td align="right">£' . number_format ($total, 2) . '</td> </tr> </table> <div align="center"><input type="submit" name="submit" value="Update My Cart" /></div> </form><p align="center">Enter a quantity of 0 to remove an item. <br /><br />'.$checkout_button.'</p>';
  6. Hi All. I can't get a redirect back to the "checkout.php" in chapter 19. I am using a personalised paypal button. Firstly; are these lines correct in checkout.php? // customer is logged in and this page has access to the customer's ID: session_id)£id); // this page receives the order total: $subtotal = $_SESSION['cart'][$row['print_id']]['quantity'] * $_SESSION['cart'][$row['print_id']]['price']; Secondly; heres the code from view_cart.php with my paypal button, but the problem is that it's not directing it back to checkout.php (above code may be incorrect?) <!--- this is where the user comes back to after they finished making the payment ---> <input type="hidden" name="notify_url" Value="http://wolfcut.co.uk/checkout.php" /> <!-- Specify details about the item that buyers will purchase. --> '.$string_of_item_names.' '.$string_of_item_amounts.' <input type="hidden" name="currency_code" value="GBP"> <!-- Display the payment button. --> <div align="center"> <input type="image" name="submit" border="0" align="center" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online"> <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" > </div> Any advice is appreciated. Thanking you!
  7. Hi All How do I add shipping_costs to view_cart.php. It's getting more complicated the more I think about real life situations because shipping costs is determined by weight. The column 'shipping_cost' already added to database, so do I plus (+) the shipping cost to quantity, or times (x) shipping cost by quantity? Can someone show me both ways as it probably depends on the situation in real life. Here's the view_cart.php section that needs the extra code: // Calculate the total and sub-totals. $subtotal = $_SESSION['cart'][$row['print_id']]['quantity'] * $_SESSION['cart'][$row['print_id']]['price']; $total += $subtotal; // Print the row: echo "\t<tr> <td align=\"left\">{$row['artist']}</td> <td align=\"left\">{$row['print_name']}</td> <td align=\"right\">£{$_SESSION['cart'][$row['print_id']]['price']}</td> <td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['print_id']}]\" value=\"{$_SESSION['cart'][$row['print_id']]['quantity']['shipping_cost']}\" /></td> <td align=\"right\">£" . number_format ($subtotal, 2) . "</td> </tr>\n";
  8. Thank guys. I managed to figure this out: here's what I ended up doing which worked: echo (is_null($row['size'])) ? '(No size information available)' : $row['size']; echo "<br />£{$row['price']} "; if($row['in_stock']=='no') echo "<br>Out of stock. Email us to let us know and we will do everything we can to get it for you."; else echo "<a href=\"add_cart.php?pid=$pid\">Add to Cart</a>"; echo "<br >"; echo "Items in stock: ".$row['stock_available']; echo "</div><br />";
  9. How do I add " In Stock" to in the view_cart.php on page 642? Adding the "in stock" field in MySQL is easy enough, but how do you add the link in the shopping car?
  10. Cheers larey, all sorted. All I had to do was place the database connection at the beginning of the scripts
  11. Hello I keep getting "Your cart is currently empty." regardless of what is added to the cart. Here are two scripts: add_cart.php and view_cart.php view_cart.php <?php # Script 19.10 - view_cart.php // This page displays the contents of the shopping cart. // This page also lets the user update the contents of the cart. // Set the page title and include the HTML header: $page_title = 'View Your Shopping Cart'; include ('header.html'); // Check if the form has been submitted (to update the cart): if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Change any quantities: foreach ($_POST['qty'] as $k => $v) { // Must be integers! $pid = (int) $k; $qty = (int) $v; if ( $qty == 0 ) { // Delete. unset ($_SESSION['cart'][$pid]); } elseif ( $qty > 0 ) { // Change quantity. $_SESSION['cart'][$pid]['quantity'] = $qty; } } // End of FOREACH. } // End of SUBMITTED IF. // Display the cart if it's not empty... if (!empty($_SESSION['cart'])) { // Retrieve all of the information for the prints in the cart: include_once('common.php'); // Connect to the database. $q = "SELECT print_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name FROM artists, prints WHERE artists.artist_id = prints.artist_id AND prints.print_id IN ("; foreach ($_SESSION['cart'] as $pid => $value) { $q .= $pid . ','; } $q = substr($q, 0, -1) . ') ORDER BY artists.last_name ASC'; $r = mysqli_query ($con, $q); // Create a form and a table: echo '<form action="view_cart.php" method="post"> <table border="0" width="90%" cellspacing="3" cellpadding="3" align="center"> <tr> <td align="left" width="30%"><b>Artist</b></td> <td align="left" width="30%"><b>Print Name</b></td> <td align="right" width="10%"><b>Price</b></td> <td align="center" width="10%"><b>Qty</b></td> <td align="right" width="10%"><b>Total Price</b></td> </tr> '; // Print each item... $total = 0; // Total cost of the order. $count=1; while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) { // Calculate the total and sub-totals. $subtotal = $_SESSION['cart'][$row['print_id']]['quantity'] * $_SESSION['cart'][$row['print_id']]['price']; $total += $subtotal; // Print the row: echo "\t<tr> <td align=\"left\">{$row['artist']}</td> <td align=\"left\">{$row['print_name']}</td> <td align=\"right\">£{$_SESSION['cart'][$row['print_id']]['price']}</td> <td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['print_id']}]\" value=\"{$_SESSION['cart'][$row['print_id']]['quantity']}\" /></td> <td align=\"right\">$" . number_format ($subtotal, 2) . "</td> </tr>\n"; $string_of_item_names = $string_of_item_names.' <input type="hidden" name="item_name_'.$count.'" Value="'.$row['print_name'].'" >'; # build item name string of all items in the basket $string_of_item_amounts = $string_of_item_amounts.' <input type="hidden" name="amount_'.$count.'" Value="'. number_format ($subtotal, 2).'" >'; # build string of prices for items in basket # use count as a reference to match names with prices in paypal $count++; } // End of the WHILE loop. mysqli_close($con); // Close the database connection. $checkout_button = ('<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <!-- Identify your business so that you can collect the payments. HELP: https://www.paypal.com/us/cgi-bin/webscr?cmd=_pdn_xclick_techview_outside https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HF00TZS We use cart becuase we have our own (third party which is us) --> <input type="hidden" name="business" value="mystore@gmail.com"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <!--- this is where the user comes back to after they finished making the payment ---> <input type="hidden" name="notify_url" Value="http://www.ecom/thankyou.php" /> <!-- Specify details about the item that buyers will purchase. --> '.$string_of_item_names.' '.$string_of_item_amounts.' <input type="hidden" name="currency_code" value="GBP"> <!-- Display the payment button. --> <input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online"> <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" > </form>'); // Print the total, close the table, and the form: echo '<tr> <td colspan="4" align="right"><b>Total:</b></td> <td align="right">$' . number_format ($total, 2) . '</td> </tr> </table> <div align="center"><input type="submit" name="submit" value="Update My Cart" /></div> </form><p align="center">Enter a quantity of 0 to remove an item. <br /><br />'.$checkout_button.'</p>'; } else { echo '<p>Your cart is currently empty.</p>'; } include ('footer.html'); ?> add_cart.php <?php # Script 19.9 - add_cart.php // This page adds prints to the shopping cart. // Set the page title and include the HTML header: $page_title = 'Add to Cart'; include ('header.html'); if (isset ($_GET['pid']) && filter_var($_GET['pid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { // Check for a print ID. $pid = $_GET['pid']; // Check if the cart already contains one of these prints; // If so, increment the quantity: if (isset($_SESSION['cart'][$pid])) { $_SESSION['cart'][$pid]['quantity']++; // Add another. // Display a message: echo '<p>Another copy of the print has been added to your shopping cart.</p>'; } else { // New product to the cart. // Get the print's price from the database: include_once('common.php'); // Connect to the database. $q = "SELECT price FROM prints WHERE print_id=$pid"; $r = mysqli_query ($con, $q); if (mysqli_num_rows($r) == 1) { // Valid print ID. // Fetch the information. list($price) = mysqli_fetch_array ($r, MYSQLI_NUM); // Add to the cart: $_SESSION['cart'][$pid] = array ('quantity' => 1, 'price' => $price); // Display a message: echo '<p>The print has been added to your shopping cart.</p>'; } else { // Not a valid print ID. echo '<div align="center">This page has been accessed in error!</div>'; } mysqli_close($con); } // End of isset($_SESSION['cart'][$pid] conditional. } else { // No print ID. echo '<div align="center">This page has been accessed in error!</div>'; } include ('footer.html'); ?> Thanks
  12. .... I think I do.... it's this segment of code that is removing items from cart and wishlist. $r = mysqli_query($dbc, "DELETE FROM carts WHERE user_session_id='$uid' AND product_type='$sp_type' AND product_id=$pid");
  13. ... I know what this looks like Larry, it's turning into a debugging lesson (lol) to debug I've done this to debug that line of code. <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); echo '<pre>'; print_r( // 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, "DELETE FROM carts WHERE user_session_id='$uid' AND product_type='$sp_type' AND product_id=$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, "SELECT id FROM carts where user_session_id='$uid' AND product_type='$sp_type' AND product_id=$pid"); if (mysqli_num_rows($r) == $qty) { // Exists in cart, UPDATE! list($cid) = mysqli_fetch_array($r, MYSQLI_NUM); $r = mysqli_query($dbc, "UPDATE carts SET quantity=quantity+$qty, 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, $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. ) echo '</pre>'; with the following error: Parse error: syntax error, unexpected T_IF, expecting ')' in /hermes/waloraweb004/b1384/moo.laissezfairelondonco/lickmyartlondon/cart.php on line 50 Any good?
  14. Hail L-U!! I can confirm that cart.php "Move to wishlist" link works fine "Remove from cart" link doesn't works at all wishlist.php "Move to cart" link works fine "Remove from wishlist" link doesn't works at all Is this what you wanted me to confirm?
  15. Happy Easter Larry. I am still encountering problems with line 1 after trying various combinations, such as removing the quotation wraps changing the quotation to single quotes removing or changing the quotation of the variables, so they don't clash with the opening quotes ... still no joy. Could it be something to do with this section of the code? // 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: 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. My testing site is: www.lickmyartlondon.co.uk It's a 'Logical Error' so I'm not getting any error messages showing on the site....... Thank you kindly Sir
×
×
  • Create New...