PDA

View Full Version : using POST and GET


swissbeets
07-07-2008, 04:46 PM
i am making a shopping cart and want the variables to be stored in the url then taken at a later time in the shopping cart, i have a while loop displaying the pictures but when i click the add to cart button , it takes me to a page and never changes the product id it stays at 8

http://localhost/bigpeckersstuff/shoppingcart.php?prod=8&action=add

heres my code

while($row = mysql_fetch_array($product_set)){



echo "<p>";
echo $row['product_name']."<br />";
echo "$".$row['product_price']."<br />"."<br />";
show_picture($row);
echo "</p>";
?>
<form action="shoppingcart.php?prod=<?php echo urlencode($row['product_id']);?>&action=add" method="post">
<input type="submit" name="submit" value="Add to Shopping Cart" />
<?php
}

am i doing somethign wrong?

lux
07-07-2008, 05:20 PM
to store the variables you have three options;

1.store the variables in a session
2. store the variables in a db record
3. store the variables in hidden form fields

for the stopping cart i would say sessions are best, unless the user has to log in first then store in the db, that way its easier to display previously incomplete orders by fetching the values from the db

davidj
07-07-2008, 05:25 PM
you dont understand the form methods properly


while($row = mysql_fetch_array($product_set)){

echo "<p>";

echo $row['product_name']."<br />";

echo "$".$row['product_price']."<br /><br />";

show_picture($row);

echo "<a href=\"shoppingcart.php?prod=".urlencode($row['product_id'])."?action=add\">".$row['product_name']."</a>";

echo "</p>";

}

?>