TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-28-2009, 01:20 PM   #1 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 6
Thanks: 0
malnomany is on a distinguished road
Default Need Help with Shopping Cart

Hello all,
thought I am not expert with PHP but I could create a simple shopping cart for my website but I need help developping it. hope someone will help me out.
I need to add a remove button to each item in the table when a user select an item from the list and have the calculation work as well. here is the website:
www.clothesmanufacture.com
anyone can help ?
malnomany is offline  
Reply With Quote
Old 05-28-2009, 06:34 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

What method are you using to store them in the first place?
__________________

Village Idiot is offline  
Reply With Quote
Old 05-28-2009, 08:03 PM   #3 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 6
Thanks: 0
malnomany is on a distinguished road
Default

Hello Village,
First, Thank you for your reply. as for the remove button. if you click Add To cart button on that page, the item you choosed will display in the running order table in the same page below. so whatever items that a customer would choose it will be displayed in the same page. so I want to add a remove button in the running order table beside each item so that the customer can remove it, but in the meanwile I want the calculation to be correct, i.e the total price.

after people choose the items and click continue, I have a script that e-mails me and e-mails the customer what they choosed, so orders aren't stored in a database.

hope you can help me add the remove button.
malnomany is offline  
Reply With Quote
Old 05-28-2009, 08:06 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

I still don't understand how you store your items to the cart in the first place. I can't help you until I know this.
__________________

Village Idiot is offline  
Reply With Quote
Old 05-28-2009, 08:09 PM   #5 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 6
Thanks: 0
malnomany is on a distinguished road
Default

maybe having a look at the entire code will help you. here's the entire code of the page:
-------------------------------------
<?php include("header.php");?>
<?
$Product_Name_Array=array('Hooded Zipper Sweatshirt','Hooded Pullover Sweatshirt', 'Crew Neck Sweatshirt – Navy', 'Crew Neck Sweatshirt – Royal', 'PE Pants', 'PE T-shirt', 'White Polo T-shirt' );
$Product_Price_Array=array('23', '22', '17', '18', '18', '7', '8' );
$Product_Size_Array=array( "Adult-S", "Adult-M", "Adult-L", "Adult-XL");//"Youth-S", "Youth-M", "Youth-L", "Youth-XL",
$Product_Quantity_Array=array(1,2,3,4,5);
if (isset($_POST['a']) ){
//$_SESSION['CustomerOrder']='';
unset($_SESSION['CustomerOrder']);
unset($_SESSION['OrderPrice']);
}
?>
<style type="text/css">
<!--
.style1 {color: #990000}
.style2 {color: #000000}
.style3 {
color: #000066;
font-weight: bold;
}
-->
</style>


<table width="92%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="title_inblock" colspan="6">
<p align="left" style="margin-top: 0; margin-bottom: 0">&nbsp; </p>
<p align="left" style="margin-top: 0; margin-bottom: 0">
<font color="#000000" size="2" face="Arial">1.&nbsp;Select your
uniform size in the dropdown box.<br>
2.&nbsp;Select the quantity of each uniform
in the dropdown box.<br>
3.&nbsp;Click the “Add to Cart” button. <br>
4.&nbsp;Your items will be displayed in the Running Order Cart.
<br>
5.&nbsp;For additional uniform size(s), repeat Steps #1 to #3.<br>
6.&nbsp;If any order items are incorrect, click on “Cancel Order” to begin a new
pre-order request. <br>
7.&nbsp;Otherwise, click “Continue”.</font><p align="left" style="margin-top: 0; margin-bottom: 0">
&nbsp;</td>
</tr></table>
<table width="92%" border="1" bordercolor="#000000" cellspacing="1" cellpadding="1">
<tr>
<td align="left" bgcolor="#FFCC00" class="style1 title_inblock_5"><div align="center"><span class="style3">No.</span></div></td>
<td align="left" bgcolor="#FFCC00" class="style1 title_inblock_5"><div align="center"><span class="style3">Product Name </span></div></td>
<td align="left" bgcolor="#FFCC00" class="style1 title_inblock_5"><div align="center"><span class="style3">Size</span></div></td>
<td align="left" bgcolor="#FFCC00" class="style1 title_inblock_5"><div align="center"><span class="style3"> Quantity </span></div></td>
<td align="left" bgcolor="#FFCC00" class="style1 title_inblock_5"><div align="center"><span class="style3">Price</span></div></td>
<td bgcolor="#FFCC00" class="title_inblock" align="left"><div align="center"></div></td>
</tr>
<?
$i=1;
foreach ($Product_Name_Array as $key=>$value){
?>
<form action="" method="post">
<tr <? if($i== 0){ $i=1;}else{?> bgcolor="#CCCC99" <? $i=0;}?>>
<td border="1" class="title_inblock"><div align="center">
<?=$key+1?>
<input type="hidden" name="IdProduct" value="<?=$key+1?>">
</div></td>
<td border="1" class="title_inblock"><div align="center">
<?=$value?>
<input type="hidden" name="ProductName" value="<?=$value?>" />
</div></td>
<td border="1" class="title_inblock"><div align="center">
<select name="Size" class="title_link" id="Size">
<? if($key != 3){?>
<option value="Youth-S">Youth-S</option>
<option value="Youth-M">Youth-M</option>
<option value="Youth-L">Youth-L</option>
<option value="Youth-XL">Youth-XL</option>
<? }?>
<option value="Adult-S">Adult-S</option>
<option value="Adult-M">Adult-M</option>
<option value="Adult-L">Adult-L</option>
<option value="Adult-XL">Adult-XL</option>
</select>
</div></td>
<td border="1" class="title_inblock"><div align="center">
<select name="Quantity" class="title_link" id="Quantity">
<? foreach($Product_Quantity_Array as $value){?>
<option value="<?=$value?>">
<?=$value?>
</option>
<? }?>
</select>
</div></td>
<td border="1" class="title_inblock"><div align="center">$
<?=$Product_Price_Array[$key]?>
<input type="hidden" name="ProductPrice" value="<?=$Product_Price_Array[$key]?>" />
</div></td>
<td border="1" class="title_inblock_link"><div align="center">
<input name="AddToCart" type="submit" class="top_menu" id="AddToCart" value="Add to Cart" />
</div></td>
</tr>
</form>
<?
}
?>
</table>
<br />
<br />

<?
if($_POST['AddToCart'] && $_POST["ProductName"] || $_SESSION['CustomerOrder']){
if( $_POST["ProductName"] ){
$Order = array();
$ShoppingSession = array();

$IdProduct = $_POST['IdProduct'];
$ProductName = $_POST['ProductName'];
$Size = $_POST['Size'];
$Quantity = $_POST['Quantity'];
$ProductPrice = strlen($_POST['ProductPrice'],4) ;

$Totalprice = number_format( $Quantity * $ProductPrice,02) ;
$OrderPrice = number_format( $_SESSION['OrderPrice'] + $Totalprice,02 );
$_SESSION['OrderPrice'] = $OrderPrice;
$CustomerOrder = $_SESSION['CustomerOrder'].'--'.$IdProduct.'|'.$ProductName.'|'.$Size.'|'.$Quant ity.'|'.$ProductPrice.'|'.$Totalprice.'|'.$OrderPr ice;
$CustomerOrder = trim($CustomerOrder,'--');
$_SESSION['CustomerOrder'] = $CustomerOrder;
// echo $CustomerOrder;
$CustomerOrderArray = split('--',$CustomerOrder);
}else{
$CustomerOrder = $_SESSION['CustomerOrder'] ;
$CustomerOrder = trim($CustomerOrder,'--');

$CustomerOrderArray = split('--',$CustomerOrder);
}
if($_REQUEST['r']){
$CustomerOrderArray = split('--',$CustomerOrder);
$CustomerOrderArray[$_REQUEST['IdShopping']]='';
$CustomerOrder = '';
foreach($CustomerOrderArray as $ke=>$val){
$CustomerOrder .= '--'.$val;

}
$_SESSION['CustomerOrder']=$CustomerOrder ;
$CustomerOrder = str_replace('----','',$CustomerOrder);
$CustomerOrder = trim($CustomerOrder,'--');
$CustomerOrderArray = split('--',$CustomerOrder);
}
if ( $CustomerOrder){
?>
<table width="92%" border="0" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td align="left" valign="top" class="title_inblock_1"><span class="style1"><b>Running Order Cart
</b></span> </td>
</tr></table>
<tr>
<td align="left" valign="top"><table width="92%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td align="center" bordercolor="#336600" bgcolor="#FFCC00" class="title_inblock_5" ><span class="style3">No.</span></td>
<td align="center" bordercolor="#336600" bgcolor="#FFCC00" class="title_inblock_5" ><span class="style3">Product Name </span></td>
<td align="center" bordercolor="#336600" bgcolor="#FFCC00" class="title_inblock_5" ><span class="style3">Size</span></td>
<td align="center" bordercolor="#336600" bgcolor="#FFCC00" class="title_inblock_5" ><span class="style3"> Quantity </span></td>
<td align="center" bordercolor="#336600" bgcolor="#FFCC00" class="title_inblock_5" ><span class="style3">Price</span></td>
<td align="center" bordercolor="#336600" bgcolor="#FFCC00" class="title_inblock_5" ><span class="style3">Total</span></td>
</tr>
<?

foreach($CustomerOrderArray as $key=>$OrderValue){

//echo $OrderValue."<br />";
$ShoppingOrderArray = explode('|',$OrderValue);
// foreach($ShoppingOrderArray as $keyShoppingOrderValue=>$ShoppingOrderValue){
// echo $ShoppingOrderValue."<br />";
// }


?>


<form action="" method="post">
<tr>
<td align="center" bordercolor="#336600" cellpadding="1" class="title_inblock_1"><?=$key+1?>
<input type="hidden" name="IdShopping" value="<?=$key?>" /><!--<input type="submit" name="r" value="remove" />--></td>
<td align="center" bordercolor="#336600" cellpadding="1" class="title_inblock_1"><?=$ShoppingOrderArray[1]?> </td>
<td align="center" bordercolor="#336600" cellpadding="1" class="title_inblock_1"><?=$ShoppingOrderArray[2]?></td>
<td align="center" bordercolor="#336600" cellpadding="1" class="title_inblock_1"><?=$ShoppingOrderArray[3]?></td>
<td align="center" bordercolor="#336600" cellpadding="1" class="title_inblock_1">$ <?=$ShoppingOrderArray[4]?></td>
<td align="center" bordercolor="#336600" cellpadding="1" class="title_inblock_1">$ <?=$ShoppingOrderArray[5]?></td>
</tr>
</form>


<?

}
?>
<tr>
<td colspan="6" bordercolor="#336600" class="title_inblock_1">&nbsp;</td>
</tr>
<tr>
<td bordercolor="#336600" class="title_inblock_1">&nbsp;</td>
<td bordercolor="#336600" class="title_inblock_1">&nbsp;</td>
<td bordercolor="#336600" class="title_inblock_1">&nbsp;</td>
<td colspan="2" align="right" bordercolor="#336600" bgcolor="#999933" class="title_inblock_1"><span class="style2"><b>Total Order Price: </b></span></td>
<td align="center" bordercolor="#336600" bgcolor="#999933" class="title_inblock_1 style2"> $ <?=$ShoppingOrderArray[6]?></td>
</tr>
</table></td>
</tr>
<tr>
<td align="right" valign="top"><div>
<div></div>
<div></div>
</div>
</br>
</br>
<table width="49%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="45%" align="center"><form method="post"> <input name="a" type="submit" class="style3" id="a" value=" Cancel Order" />
</form></td>
<td width="55%" align="center"><form method="post">
<input name="button" type="button" class="style3" onclick="window.location='confirmOrder.php'" value=" Continue" />
</form></td>
</tr>
</table><table><tr><td></td>
</tr>
</table>
<?
}
}
?>
<?php include("footer.php"); ?>
malnomany is offline  
Reply With Quote
Old 05-28-2009, 09:32 PM   #6 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 6
Thanks: 0
malnomany is on a distinguished road
Default

I added the remove button beside each item, the problem is when you click the remove button , it miss up the caculation. when you remove item and add another item, it doesnt calculate right. do you have an idea how to fix it ?
malnomany is offline  
Reply With Quote
Old 05-28-2009, 09:33 PM   #7 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 6
Thanks: 0
malnomany is on a distinguished road
Default

here is the code the does the calculation
PHP Code:
<? 
if($_POST['AddToCart'] && $_POST["ProductName"] || $_SESSION['CustomerOrder']){ 
if( 
$_POST["ProductName"] ){ 
$Order = array(); 
$ShoppingSession = array(); 

$IdProduct $_POST['IdProduct']; 
$ProductName $_POST['ProductName']; 
$Size $_POST['Size']; 
$Quantity $_POST['Quantity']; 
$ProductPrice = ($_POST['ProductPrice']) ; 

$Totalprice number_format$Quantity $ProductPrice,02) ; 
$OrderPrice number_format$_SESSION['OrderPrice'] + $Totalprice,02 ); 
$_SESSION['OrderPrice'] = $OrderPrice
$CustomerOrder $_SESSION['CustomerOrder'].'--'.$IdProduct.'|'.$ProductName.'|'.$Size.'|'.$Quantity.'|'.$ProductPrice.'|'.$Totalprice.'|'.$OrderPrice
$CustomerOrder trim($CustomerOrder,'--'); 
$_SESSION['CustomerOrder'] = $CustomerOrder
// echo $CustomerOrder; 
$CustomerOrderArray split('--',$CustomerOrder); 
}else{ 
$CustomerOrder $_SESSION['CustomerOrder'] ; 
$CustomerOrder trim($CustomerOrder,'--'); 

$CustomerOrderArray split('--',$CustomerOrder); 

if(
$_REQUEST['r']){ 
$CustomerOrderArray split('--',$CustomerOrder); 
$CustomerOrderArray[$_REQUEST['IdShopping']]=''
$CustomerOrder ''
foreach(
$CustomerOrderArray as $ke=>$val){ 
$CustomerOrder .= '--'.$val


$_SESSION['CustomerOrder']=$CustomerOrder 
$CustomerOrder str_replace('----','',$CustomerOrder); 
$CustomerOrder trim($CustomerOrder,'--'); 
$CustomerOrderArray split('--',$CustomerOrder); 

if ( 
$CustomerOrder){ 
?>  
           

malnomany 
View Public Profile 
Find More Posts by malnomany 
Add malnomany to Your Contacts
malnomany is offline  
Reply With Quote
Old 05-29-2009, 03:12 AM   #8 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

No offense, but I can't read that code. It is not indented or commented at all. You also seem to be using a self-made text delimited storage method that I do not know, which makes things even harder.
__________________

Village Idiot is offline  
Reply With Quote
Old 05-29-2009, 06:39 AM   #9 (permalink)
The Acquainted
 
Hightower's Avatar
 
Join Date: May 2009
Location: Durham, UK
Posts: 134
Thanks: 9
Hightower is on a distinguished road
Default

Holy cow man, have you heard the term "comments"? I honestly couldn't get into your code - just kept looking and thinking "what a mess". Make it human readable.

You may know what does what now, but I guarantee you, when you come to edit it next year you'd be just as lost as we are!
__________________
Hightower's Softpolio
Send a message via MSN to Hightower
Hightower is offline  
Reply With Quote
Old 05-29-2009, 09:04 AM   #10 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 6
Thanks: 0
malnomany is on a distinguished road
Default

I am sorry to bother you but I am not the one who wrote this code as I am not a programmer , I asked someone to make a simple order form for me but it seems he isn't an expert with php. at any rate, can someone write a code that does the same job ? all I want is an order form like this one where customers can choose the items I supply then e-mail me their orders. sorry once again for bothering you.
malnomany is offline  
Reply With Quote
Old 05-31-2009, 11:13 AM   #11 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Or, you could learn PHP and build it yourself?
We'll gladly help you with any issues you might have with your code, but I doubt anyone here will work and script a complete code for you, especially when it's a complex system like a shopping cart - well, not for free anyways.
__________________
Tanax is offline  
Reply With Quote
Old 06-03-2009, 03:39 AM   #12 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 7
Thanks: 0
zongliang is on a distinguished road
Default

I am developed a shopping cart, I used Jquery to remove it from table. After all behavir, then record all data into database.
zongliang is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:58 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design