...

View Full Version : Add to Shopping Cart



Cerby
10-28-2007, 07:33 PM
OK, For testing/development purposes, I have the following code to display all the products contained inside the database.
How do I display each record/product along with a button to add the product to the shopping cart/session?


mysql_select_db("Data", $con);

$result = mysql_query("SELECT * FROM Products");

while($row = mysql_fetch_array($result))
{
echo $row['Name'];
echo $row['Price'];
}

mysql_close($con);
?>

robojob
10-28-2007, 07:49 PM
just add your button in after echo $row['Price']; but before the closing }

you could use a graphic button, a form or text. for example.



mysql_select_db("Data", $con);

$result = mysql_query("SELECT * FROM Products");

while($row = mysql_fetch_array($result))
{
echo $row['Name'];
echo $row['Price'];
echo '<a href="add_to_cart.php">Add to Cart</a>';
}

mysql_close($con);
?>

you would need to add in the id of the product so the add_to_cart page knows which product you have selected.

Cerby
10-28-2007, 08:00 PM
OK, Cheers :) What code goes inside the add_to_cart.php file?

robojob
10-28-2007, 08:04 PM
might i suggest you take a look at: http://www.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum