I am trying to create a simple 'shopping cart' pages.
first page - shopindex.php
In this page i've just select field from products table and displayed with 'text box' to enter user's quantity and 'Button'(redirect to shoppingcart.php) to add values to cart.
Ive passed the value of quantity(name of the text box) using sessions with below code in shoppingcart.php..
<?php
session_start();
$_SESSION['cart'] = $_POST['quantity'];
//$_SESSION['id'] = $_POST[$column2];
$cart = $_SESSION['cart'];
//$id = $_SESSION['id'];
echo "$cart";
//echo "$id";
?>
My shopindex.php code is below:
<?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> Index page</title>
</head>
<body>
<h1><center> Products </center></h1>
<?php
mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("classicmodels")or die("cannot select DB");
$query = "SELECT productName, productCode, buyPrice, quantityInStock FROM products";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num)
{
$column1 = mysql_result($result,$i,"productName");
$column2 = mysql_result($result,$i,"productCode");
$column3 = mysql_result($result,$i,"buyPrice");
$column4 = mysql_result($result,$i,"quantityInStock");
?>
<form name="form1" method="post" action="shoppingcart.php">
<table border="0" cellspacing="5">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Product Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Prococt Code</font></th>
<th><font face="Arial, Helvetica, sans-serif">Price</font></th>
<th><font face="Arial, Helvetica, sans-serif">Quantity in Stock</font></th>
<th><font face="Arial, Helvetica, sans-serif">quantity</font></th>
<th><font face="Arial, Helvetica, sans-serif">Add to Cart</font></th>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $column1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $column2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $column3; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $column4; ?></font></td>
<td><input type ="text" name = "quantity" /></td>
<td><input type="submit" name="add" value="Add to Cart" /></td>
</tr>
</table>
</form>
<?php
$i++;
}
?>
</body>
</html>
'quantity' i've already passed using text 'name' attribute.
My question is
how do i pass the correspondent product code of selected product in this form using session or any other method?
I am so confused, pls somebody help me.
(pardon my poor english):quiet: