some code i cant understand please help
Posted: Mon Sep 21, 2009 10:16 pm
Hi guys im not sure what this php code is doing below i know if you click on the add cart button it adds more quantity of the product i understand that. But i do not understand the logic in the coding with the if statements. Iv put some comments below in the code to show you where im not understanding. If someone could explain to me i would appreciate it thanks.
Code: Select all
<?php
if (isset($_POST['submit'])) //isset is used to set the variable to turn it on basically remember what they
//added to the cart
{
if($_SESSION['item']==$_POST['h1']) //does this actually do anything?
{
$_SESSION['qty'] = $_SESSION['qty'] + 1; //the more you click add cart the more the qty increments and gets stored in the session
//array
}
else
{
$_SESSION['item'] = $_POST['h1']; //what do these two lines below do?
$_SESSION['price']= $_POST['h2'];
}
$_SESSION['itemname'][$_SESSION['item']] = $_SESSION['item']; //i dont understand this part of the code either
$_SESSION['itemqty'][$_SESSION['item']] = $_SESSION['qty'];
$_SESSION['itemprice'][$_SESSION['item']] = $_SESSION['price'];
}
?>
<table>
<tr>
<td>
<img src="eric.jpg"/>
</td>
<td>This product is on clearance. New stock needs to come in and all the old stock needs to go. Hurry till offers end!!</td></tr>
<tr><td><form action="erricsson.php" method="post"><input type="submit"
name="submit" value="Add to cart"/><input type="hidden" name="h1"
value="k508i" /><input type="hidden" name="h2" value="400"/></form> </td></tr>
</table>
<a href="cart.php">View your cart</a>
</body>
</html>