kanchatchai Posted September 7, 2012 Share Posted September 7, 2012 (edited) code without database. (Idia only) <?phpsession_start();/*$_SESSION["customer_id"]=77;//test customer_idecho 'customer id='.$_SESSION["customer_id"].'<br/>';*//*-------------------------------------- Show Product --------------------------------------*/?><FORM Name="Form1" Method="POST"><input type="hidden" name="productid" value ="4">Product 4: aa <input type="text" name="count" value="1" size="4" maxlength="4" > <input type="submit" name="button" id="button" value="Add to Card" /> </form><FORM Name="Form1" Method="POST"><input type="hidden" name="productid" value ="5">Product 5: bb <input type="text" name="count" value="1" size="4" maxlength="4" > <input type="submit" name="button" id="button" value="Add to Card" /> </form><FORM Name="Form1" Method="POST"><input type="hidden" name="productid" value ="7">Product 7: cc <input type="text" name="count" value="1" size="4" maxlength="4" > <input type="submit" name="button" id="button" value="Add to Card" /> </form> <?PHP /*-------------------------------------- Add--------------------------------------*/if (isset($_POST['count'])){if (isset($_SESSION["product"][$_POST['productid']])) $_SESSION['product'][$_POST['productid']]=$_SESSION['product'][$_POST['productid']]+$_POST['count'];else $_SESSION['product'][$_POST['productid']]=$_POST['count'];}/*-------------------------------------- Delete --------------------------------------*/ if (isset($_POST['delete_selected'])) { if (isset($_POST['check'])) foreach($_POST['check'] as $key=>$value){ unset ($_SESSION['product'][$key]); //echo $key; } } /*-------------------------------------- Update --------------------------------------*/ if (isset($_POST['update'])) { if (isset($_POST['new_count'])) foreach($_POST['new_count'] as $key=>$value){ //Can Use... //$_SESSION['product'][$key]=$_POST['value'][$key]; //or Use ... $_SESSION['product'][$key]=$value; } //echo '<br/>value updated<br/><br/>'; } /*-------------------------------------- Show Cart --------------------------------------*/ if (isset($_SESSION['product'])){echo '<b>Your Cart</b><br/><FORM Name="Form1" Method="POST">'; foreach($_SESSION['product'] as $key=>$value){ echo '<input type="checkbox" name="check['.$key.']" >'.$key.'=<input type="text" name="new_count['.$key.']" value="'.$_SESSION['product'][$key].'"><br/>'; } echo '<input type="submit" name="delete_selected" value="Delete Selected" />'; echo '<input type="submit" name="update" value="Update" />'; echo '<input type="submit" name="buynow" value="Buy Now" />'; echo '</form>'; } // If Click Update show ..Updated... if (isset($_POST['update'])) echo "Your Card Updated"; if (isset($_POST['buynow'])) { if (isset($_SESSION["customer_id"])) { /*Update To Database ...and show user... */ echo "Your Cart Completed"; //Next Clear Cart Session unset($_SESSION['product']); } else { echo "Please Login to Complete Cart.";} } ?> Edited September 8, 2012 by kanchatchai Link to comment Share on other sites More sharing options...
niche Posted September 7, 2012 Share Posted September 7, 2012 ??? Link to comment Share on other sites More sharing options...
kanchatchai Posted October 5, 2012 Author Share Posted October 5, 2012 (edited) <?PHPinclude('connect.php');@session_start();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Product For You</title><style type="text/css"><!-- table{border-collapse:collapse;}table,th, td{border: 1px solid #8AB1B9;} #left_sidebar {float: left;width: 22%; padding: 15px 0;/* background-color: #ABE6ED;*/border: 1px solid #8AB1B9;}#right_sidebar {float: right;width: 23%;/* background-color: #ABE6ED;*/border: 1px solid #8AB1B9;padding: 15px 0;}#mainContent {margin: 0 24% 0 23.5%;}#productbox{/*background-color: #D4EAFC;*/border: 1px solid #A7B8C5;width:220px;padding:10px;margin:3px;float:left;} --></style></head><body> <div id="left_sidebar">Left Sidebar </div> <div id="right_sidebar"> <?PHP /*-------------------------------------- Add--------------------------------------*/if (isset($_POST['count'])){if (isset($_SESSION["product"][$_POST['productid']])) $_SESSION['product'][$_POST['productid']]=$_SESSION['product'][$_POST['productid']]+$_POST['count'];else $_SESSION['product'][$_POST['productid']]=$_POST['count'];}/*-------------------------------------- Delete --------------------------------------*/if (isset($_POST['delete_selected'])){ if (isset($_POST['check'])) foreach($_POST['check'] as $key=>$value){ unset ($_SESSION['product'][$key]); //echo $key; }}/*-------------------------------------- Update --------------------------------------*/ if (isset($_POST['update'])){ if (isset($_POST['new_count'])) foreach($_POST['new_count'] as $key=>$value){ //Can Use... //$_SESSION['product'][$key]=$_POST['value'][$key]; //or Use ... $_SESSION['product'][$key]=$value; } //echo '<br/>value updated<br/><br/>';} /*-------------------------------------- Show Cart --------------------------------------*/if (isset($_SESSION['product'])){echo '<b>Your Cart</b><br/><FORM Name="Form1" Method="POST">';echo '<table id="table_border1" ><tr ><th >Select</th><th>Name</th><th>Price</th><th>Count</th><th>Sum</th></tr>'; $total=0; foreach($_SESSION['product'] as $key=>$value) { echo '<tr ><td><input type="checkbox" name="check['.$key.']" >#'.$key.'</td>'; $result_select_product = mysql_query("SELECT * FROM tbl_product where product_id=".$key); while($row_select_product = mysql_fetch_array($result_select_product)) { $price=0; echo '<td>'.$row_select_product['product_name'].'</td>'; echo '<td align="right">'.$row_select_product['product_price'].'</td>'; $price=$row_select_product['product_price'];} echo '<td><input type="text" size="4" Style="text-align: right;" name="new_count['.$key.']" value="'.$_SESSION['product'][$key].'"></td>';$count_x_price=($price*$_SESSION['product'][$key]);$total=$total+$count_x_price;echo ' <td align="right">'.$count_x_price.'</td>';//sumecho '</tr>'; }echo ' <td colspan="4" align="center" ><b>TOTAL</b></td> <td align="right"><b>'.$total.'</b></td>';echo '</table>'; echo '<input type="submit" name="delete_selected" value="Delete Selected" />';echo '<input type="submit" name="update" value="Update" />';echo '<input type="submit" name="buynow" value="Buy Now" />';echo '</form>'; } // If Click Update show ..Updated... if (isset($_POST['update'])) echo "Your cart Updated"; if (isset($_POST['buynow'])) { if (isset($_SESSION["customer_id"])) { require('update_cart.php'); /*Update To Database ... ... ... ...and show user... */ echo "Your Cart Completed"; //Next Clear Cart Session unset($_SESSION['product']); } else { echo "Please Login to Complete Cart.";} } //End Show Cart ?> </div> <div id="mainContent"><?PHPif (isset($_SESSION['admin_id'])){echo '<a href="tbl_product_insert.php"><img src="icon/add.png" alt="+Add" title="Add New"/></a>';} $result_tbl_product = mysql_query("SELECT * FROM tbl_product"); while($row_tbl_product = mysql_fetch_array($result_tbl_product)) { ?> <div id="productbox"> <FORM Name="Form1" Method="POST"> <input type="hidden" name="productid" value ="<?PHP echo $row_tbl_product['product_id'];?>"> <b>Image:</b><br/> <img src="<?PHP echo $row_tbl_product['product_image']?>"><br/> <b> <?PHP echo "#".$row_tbl_product['product_id']." ".$row_tbl_product['product_name'];?></b><br/> <b>Price:</b> <?PHP echo $row_tbl_product['product_price'];?><br/> <b>Get it:</b> <input type="text" name="count" value="1" size="4" maxlength="4" Style="text-align: right;"> <input type="submit" name="button" id="button" value="Add to cart" /> </form></div><?PHP } ?></div><?PHP/*echo "Sessions";echo "<pre>";print_r($_SESSION);echo "</pre>";*/?></body></html> <?PHP mysql_close($con); ?> Edited October 28, 2012 by kanchatchai Link to comment Share on other sites More sharing options...
boen_robot Posted October 5, 2012 Share Posted October 5, 2012 Dude... if you have an idea about a universal shopping cart system... publish it in some code repository (GitHub, SourceForge, etc.), not in forums. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now