Note that there are some explanatory texts on larger screens.

plurals
  1. PODisabling checkout button from shopping cart - php
    primarykey
    data
    text
    <p>I am trying to setup a “view shopping cart/basket” page within a site in which logged in users earn points/credits. Once they earn a certain amount of these points they can then go to a shopping cart and pay with these points only. (No money changes hands, so no paypal/checkout/shipping/taxes etc are involved)</p> <p><p>So far I have got the login, points total table, add product to cart and change of quantity feature to work.<br/></p> <p>What I am trying to do on this ‘view_cart.php’ page (code below) is to make the ‘Checkout’ link (submit_cart.php) disappear or be disabled if the user's points total is less than the total shopping cart price. Is there anyway I can do this on this script? The ‘You don’t have enough points to proceed to checkout’ prompt works if this is the case but if I can this checkout link to disappear that would be great.</p> <p>My php knowledge is limited as I’m more of a front end designer but please feel free to offer any suggestions or changes of approach. Thanks!</p> <pre><code>&lt;?php $page_title = 'Your Rewards Shopping Cart'; include ('./includes/header.html'); if (!isset($_SESSION['users_id'])) { $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); } $url .= '/login.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } $rwp = $_SESSION['reward_user_points']; $problem = FALSE; if (isset($_POST['submitted'])) { foreach ($_POST['qty'] as $k =&gt; $v) { $pid = (int) $k; $qty = (int) $v; if ( $qty == 0 ) { unset ($_SESSION['cart'][$pid]); } elseif ( $qty &gt; 0 ) { $_SESSION['cart'][$pid] ['quantity'] = $qty; } } // End of FOREACH. } // End of SUBMITTED IF. $empty = TRUE; if (isset ($_SESSION['cart'])) { foreach ($_SESSION['cart'] as $key =&gt;$value) { if (isset($value)) { $empty = FALSE; break; // Leave the loop. } } // End of FOREACH. } // End of ISSET IF. if (!$empty) { require_once ('/MySQL/database.php'); $query = "SELECT users_id, reward_user_points FROM reward_points WHERE reward_points.users_id = users.users_id"; $result = mysql_query($query); $query = "SELECT products_id, products_name FROM categories, products WHERE categories.categories_id = products.categories_id AND products.products_id IN (";foreach ($_SESSION['cart'] as $pid =&gt;$value) { $query .= $pid . ','; } $query = substr ($query, 0, -1) . ') ORDER BY categories.categories_name ASC'; $result = mysql_query($query); ?&gt; &lt;h1&gt;Your Shopping Cart&lt;/h1&gt; &lt;div id="sidebar"&gt; &lt;div id="statusbar"&gt; &lt;p&gt;&lt;span class="statusbar_highlight"&gt;Name:&lt;/span&gt;&lt;br /&gt; &lt;?php echo " {$_SESSION['users_first_name']} " . " {$_SESSION['users_surname']}&lt;br&gt; ";?&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="statusbar_highlight"&gt;Outlet:&lt;/span&gt;&lt;br /&gt; &lt;?php echo " {$_SESSION['users_outlet']} ";?&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="statusbar_highlight"&gt;Sales Number:&lt;/span&gt;&lt;br /&gt; &lt;?php echo " {$_SESSION['users_sales_no']} ";?&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="statusbar_highlight"&gt;My Points:&lt;/span&gt;&lt;br /&gt; &lt;font size="+1"&gt;&lt;?php echo " {$_SESSION['reward_user_points']} ";?&gt;&lt;/font&gt;&lt;/p&gt; &lt;/div&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;/div&gt; &lt;div id="maincontent_inner"&gt; &lt;div id="maincontent_inner2"&gt; &lt;?php echo '&lt;table border="0" width="100%" cellspacing="1" cellpadding="5" align="center"&gt; &lt;tr class="top"&gt; &lt;td align="left" width="46%"&gt;&lt;b&gt;Reward Product&lt;/b&gt;&lt;/td&gt; &lt;td align="right" width="18%"&gt;&lt;b&gt;Price&lt;/b&gt;&lt;/td&gt; &lt;td align="center" width="16%"&gt;&lt;b&gt;Qty&lt;/b&gt;&lt;/td&gt; &lt;td align="right" width="20%"&gt;&lt;b&gt;Sub Total&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt; &lt;form action="view_cart.php" method="post"&gt;'; $total = 0; // Total cost of the order. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // Total and subtotals. $subtotal = $_SESSION['cart'][$row ['products_id']]['quantity'] * $_SESSION['cart'][$row ['products_id']]['price']; $total += $subtotal; if ($rwp &gt;= $total) { } else { echo "You do not have enought points to proceed to checkout &lt;br /&gt;"; } // Print the row. echo " &lt;tr&gt; &lt;td align=\"left\"&gt;{$row['products_name']}&lt;/td&gt; &lt;td align=\"right\"&gt;{$_SESSION['cart'][$row['products_id']] ['price']} pts&lt;/td&gt; &lt;td align=\"center\"&gt;&lt;input type=\"text\" size=\"3\" name=\"qty[{$row['products_id']}]\" value=\"{$_SESSION['cart'][$row['products_id']]['quantity']}\" /&gt;&lt;/td&gt; &lt;td align=\"right\"&gt;" . number_format ($subtotal) . " pts&lt;/td&gt; &lt;/tr&gt;\n"; } // End of the WHILE loop. mysql_close($dbc); // Close the database connection. // products the footer, close the table, and the form. echo ' &lt;tr class="even"&gt; &lt;td colspan="3" align="right"&gt;&lt;b&gt; TOTAL:&lt;b&gt;&lt;/td&gt; &lt;td align="right"&gt;&lt;b&gt;' . number_format ($total) . ' pts &lt;/b&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;div align="center"&gt;&lt;input type="submit" name="submit" value="Update" /&gt; &lt;input type="hidden" name="submitted"value="TRUE" /&gt; &lt;/form&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt; &lt;p&gt;&lt;a href="browse_rewards.php"&gt;&lt;img src="images/but_continue.png" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="submit_cart.php"&gt;&lt;img src="images/but_checkout.png" /&gt;&lt;/a&gt;&lt;/p&gt;'; } else { echo '&lt;h1&gt;Shopping Cart&lt;/h1&gt;&lt;p&gt;Your cart is currently empty.&lt;/p&gt; &lt;p&gt;&lt;a href="browse_rewards.php"&gt;&lt;img src="images/but_continue.png" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;div id="maincontent_inner"&gt; &lt;div id="maincontent_inner2"&gt; '; } ?&gt; &lt;br /&gt; &lt;p&gt; &lt;span class="extras"&gt;&lt;strong&gt;Please Note the following:&lt;/strong&gt;&lt;br /&gt; 1. To delete any item off your cart, simply type in '0' and click 'Update'&lt;br /&gt; 2. To add in more than one item, simply click the desired amount and click 'Update'&lt;br /&gt; 3. Your cart will be emptied upon logging out of your session&lt;br /&gt; &lt;/span&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php include ('./includes/footer.html'); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload