hi,
im pretty new with PHP. im busy buiding an onlineshop, im pretty far with the site the only things is that im now stuck with the shopcart...
what i try to accomplish is that a user can add products as much as he/she wants. When a user adds a product i store the id and qty in a session. When i they continue shopping i want to add the new product under/above the existing one.
as long as the user dont check out, i will want to keep the products in the sesion (has this format $_SESSION['winkelwagen']['products']['pid']=$pid😉
Adding this first product is no problem, when i update and/or add a new product it override the first product plus twice.
So at this point im lost, i hope somebody can help me out on this one,
here beneath is the code and form im using.
thanks a mil
<?php
if(isset($_SESSION['winkelwagen']))
{
//query for new to be added product
$_SESSION['winkelwagen']['products']['pid']=$pid //($pid from db,added to the session)
$winkelwagen=$_SESSION['winkelwagen']
if(is_array(winkelwagen)
{
foreach(winkelwagen as $prodid=>$qty) //begin foreach
{
//check to see if a product is already added
if($prodid != $pid)
{
//add new product to Session
}
else
{
update quantity
}
?>
<tr>
<input type="hidden" name="pid[]" value="<?php echo $pid;?>">
<td bgcolor="<?php echo $box_field_color; ?>" class="boxmaintext"> <?php echo "<b>".$productname." ".$producttype." ".$productnummer."</b><br>".$productbeschrijving; ?></td>
<td width="5" bgcolor="<?php echo $box_field_color; ?>"> </td><input type="hidden" name="action" value="submitted">
<td width="40" align="center" bgcolor="<?php echo $box_field_color; ?>"><input type="text" name="qty[] "value="<?php echo $pqty['qty']; ?>" maxlength="3" size="2"><br><input type="submit" name="submit" value="update me!"></td>
</form>
<td width="5" bgcolor="<?php echo $box_field_color; ?"> </td>
<td width="100" align="right" bgcolor="<?php echo ox_field_color; ?"
class="boxmaintext"><?php echo $prodprice; ?> </td>
<td width="5" bgcolor="<?php echo $box_field_color; ?>"> </td>
<td width="78" align="right" bgcolor="<?php echo $box_field_color; ?>" class="boxmaintext"><?php echo $prodprice; ?> </td>
<td width="5" bgcolor="<?php echo $box_field_color; ?>"><br></td>
<td width="35" align="center" bgcolor="<?php echo $box_field_color; ?>"><input type="checkbox" name="checkbox" value="checkbox"></td>
</tr>
<tr>
<td bgcolor="<?php echo $box_field_color; ?>" class="boxfield"> <?php echo $shop_system_details; ?></td>
<td colspan=8 bgcolor="<?php echo $box_field_color; ?>" class="boxfield"> </td>
</tr>
<tr>
<td colspan=9 style="border-top: 1px solid <?php echo $shop_table_top_bgcolor; ?>;"><img src"images/spacer.gif" alt=" " width="1" height="1"></td>
</tr>
<?php
} //end foreach
} //end inner if
} //end outer if
else
{
//first selected product will paass here (select from db)
//...and displayed in the form shown above
//here the $SESSION is initialized
$SESSION['winkelwagen']['products']['pid']=$pid //(uit db)
$_SESSION['winkelwagen']['products']['qty']=$qty //(uit db)
}
?>