PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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>
if($_SESSION['item']==$_POST['h1']) //does this actually do anything?
i think this is checking to see if it's the same item as you had previously in your array. if so it adds an extra 1 to the quantity if not then it sets up a new item in the session. which is