Jump to content

Homemade Shopping Cart Question


ImJustBrndn

Recommended Posts

It's set via session. This is the heart of the cart code minus the site its built around. Thanks again.

[code]<?
include "functions_cart.php";
$totalvalue = 0;

session_start();
// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
$_SESSION["cart"] = NULL;
}

if (validate() == TRUE && $_SESSION["cart"] != NULL) {

foreach ($_SESSION["cart"] as $key => $session_data) {

list($ses_id, $ses_quan) = $session_data;

// call database connect function
db_connect();
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$ses_id."");
$item = mysql_fetch_array($sel_products);

$totalvalue = $totalvalue + $shipping + ($item["price"]*$ses_quan);
$subtotal = ($item["price"]*$ses_quan);
$shipping = (3.00*ses_quan);

?>
<tr>
<td class="style11"><div align="center"><a href="<? echo "phpCart_manage.php?act=del&pid=".$ses_id; ?>"><img src="remove_button.gif" width="60" height="21" border="0"></a></div></td>
<td class="style11"><input name="newquan[]" type="text" id="newquan[]3" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>"></td>
<td class="style11"><? echo $item["product"]; ?></td>
<td class="style11"><? echo $cur_symbol."".number_format($item["price"], 2, '.', ''); ?></td>
<td class="style11"><? echo $cur_symbol."".number_format($subtotal, 2, '.', ''); ?></td>
</tr>
<?
} // end foreach loop

} elseif ($_SESSION["cart"] == NULL) {

echo "<td colspan=\"5\"><center><p>Your basket is currently empty.</p></center></td>";

} else {

echo "<td colspan=\"5\"><center><p>Unknown Error.</p></center></td>";

}
?>
<tr>
<td class="style11">&nbsp;</td>
<td class="style11">&nbsp;</td>
<td class="style11">&nbsp;</td>
<td class="style11"><strong>Shipping</strong></td>
<td class="style11"><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?>&nbsp;</td>
</tr>
<tr>
  <td class="style11">&nbsp;</td>
  <td class="style11"><? if ($_SESSION["cart"] != NULL) { echo "<input name=\"UpdateChg\" type=\"submit\" id=\"UpdateChg\" value=\"Update\">"; } ?></td>
  <td class="style11"><a href="index.php">Continue Shopping</a></td>
  <td class="style11"><strong>Total</strong></td>
  <td class="style11"><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?></td>
</tr>
<tr>
  <td class="style11">&nbsp;</td>
  <td class="style11">&nbsp;</td>
  <td class="style11">&nbsp;</td>
  <td class="style11">&nbsp;</td>
  <td class="style11">&nbsp;</td>
  </tr>
<tr>
  <td colspan="5" class="style11">&nbsp;</td>
  </tr>
</table>
</form>[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.