Jump to content

problem implementing shopping cart


Duke555

Recommended Posts

i am still very much stuck in my shopping cart application.

 

i believe the problem is in the following line of code:

		<td align="left"><input type="text" size="3" name="$name" value='<?echo $_POST["cart"]["$name"];?>' /></td>

when i click on 'submit' (see full code of products.php below) it takes me to my_cart.php where i tried checking to make sure the _POST[] came out with names of products and values submitted by the user.

in stead i get the following output:

 

printing _POST[cart]

$name---

 

for the code:

echo "printing _POST[cart]<br>";
foreach($_POST as $k => $v){
echo "$k---$v<br>";
}

 

please help me figure it out thank you :)

 

//beginning of the FORM
echo '<form action="my_cart.php" name="cart" method="post" >';

//traversing outer array in this loop
//'name' is the 'key' and 'description' is the 'value' of this outer array
while (list($name, $description) = each($product))
{
	//calculating grand total of an item's 'price' and 'shipping' which are stored in the inner
	//array and are pointed by the keys 'price' and 'shipping' respectively
	$grand_total = calc_total($description[Price], $description[shipping]);
	$shipping = $description[shipping] * $description[Price];
?>
<tr>
	<td align="left"><? echo $name;?></td>
	<td align="left"><? echo number_format($description[Price], 2);?></td>
	<td align="left"><? echo number_format($shipping, 2); ?></td>
	<td align="left"><input type="text" size="3" name="$name" value='<?echo $_POST["cart"]["$name"];?>' /></td>
		<td align="right"><? echo number_format($grand_total, 2);?></td>
	</tr>
	<?
}
	// Print the footer, close the table, and the form:
	?><tr>
		<td colspan="4" align="right"><b>Total:</b></td>
		<!--<td align="right">$' . number_format ($total, 2) . '</td>-->
		<td align="center">TEST</td>
	</tr>	
	<tr>
		<td colspan="6" align="center">TEST</td>
	</tr>
	</table><div align="center"><input type=submit value="SUBMIT"></div>
</form>

Link to comment
https://forums.phpfreaks.com/topic/170921-problem-implementing-shopping-cart/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.