meme
03-25-2007, 06:28 AM
Hi,
I am writing a simple storefront pages but I am facing 2 problems I hope you can help me with as my deadline is today!
1) I am collecting data from a table in a form, using a while loop (based on user selection. when I try to display the posted data in the following page. I get the same data repeated 6 times.
2) I do not know how to transfer a variable value into the next page.
Here is my code:
page1:
$counter = 1;
while ($i = mysql_fetch_assoc($results)){
echo "<tr><td>".$i["product_name"]."</td>";
//hidden field to hold the product name
echo "<input type=hidden name='prodname".$counter."' value=".$i["product_name"]." >";
echo "<td>£".$i["product_price"]."</td>";
//hidden field to hold the product price
echo "<input type=hidden name='prodprice".$counter."' value=".$i["product_price"]." >";
/hidden field to hold the product code
echo "<input type=hidden name='prodcode".$counter."' value=".$i["product_code"]." >";
$counter++;
}
if ($_POST[CD] && $_POST[Book]){
$pnp=6;
$total = 45.98;
echo "<tr><td><b>Postage and Packaging</b></td><td>£6.00</td></tr>";
echo "<tr><td><b>Total</b></td><td>£45.98</td></tr>";
}
else {
$pnp=4;
$total = 23.99;
echo "<tr><td><b>Postage and Packaging</b></td><td>£4.00</td></tr>";
echo "<tr><td><b>Total</b></td><td>£23.99</td></tr>";
}
echo "</table>";
echo "<table align = center><tr><td><input type='reset' name='reset' value='Change your selection'></td><td width=20%> </td><td><input type='submit' name='submit' value='Proceed to checkout'></td></tr></table></form>";
}
?>
The second page code:
if( isset( $_POST['submit'] ) )
{
foreach ($_POST as $key => $value) {
//For debugging - prints every iteration of the form posted data
echo "<pre>" . print_r($_POST, 1) . "</pre>";
echo "$total";
}
}
This prints the same data 6 times; like here:
Array
(
[prodname1] => Book
[prodprice1] => 19.99
[prodcode1] => 1
[prodname2] => CD
[prodprice2] => 19.99
[prodcode2] => 2
[submit] => Proceed to checkout
)
Array
(
[prodname1] => Book
[prodprice1] => 19.99
[prodcode1] => 1
[prodname2] => CD
[prodprice2] => 19.99
[prodcode2] => 2
[submit] => Proceed to checkout
)
AND SO ON..............
ALSO I am not sure how to transfer the $total value to the next page.
Many thanks.
I am writing a simple storefront pages but I am facing 2 problems I hope you can help me with as my deadline is today!
1) I am collecting data from a table in a form, using a while loop (based on user selection. when I try to display the posted data in the following page. I get the same data repeated 6 times.
2) I do not know how to transfer a variable value into the next page.
Here is my code:
page1:
$counter = 1;
while ($i = mysql_fetch_assoc($results)){
echo "<tr><td>".$i["product_name"]."</td>";
//hidden field to hold the product name
echo "<input type=hidden name='prodname".$counter."' value=".$i["product_name"]." >";
echo "<td>£".$i["product_price"]."</td>";
//hidden field to hold the product price
echo "<input type=hidden name='prodprice".$counter."' value=".$i["product_price"]." >";
/hidden field to hold the product code
echo "<input type=hidden name='prodcode".$counter."' value=".$i["product_code"]." >";
$counter++;
}
if ($_POST[CD] && $_POST[Book]){
$pnp=6;
$total = 45.98;
echo "<tr><td><b>Postage and Packaging</b></td><td>£6.00</td></tr>";
echo "<tr><td><b>Total</b></td><td>£45.98</td></tr>";
}
else {
$pnp=4;
$total = 23.99;
echo "<tr><td><b>Postage and Packaging</b></td><td>£4.00</td></tr>";
echo "<tr><td><b>Total</b></td><td>£23.99</td></tr>";
}
echo "</table>";
echo "<table align = center><tr><td><input type='reset' name='reset' value='Change your selection'></td><td width=20%> </td><td><input type='submit' name='submit' value='Proceed to checkout'></td></tr></table></form>";
}
?>
The second page code:
if( isset( $_POST['submit'] ) )
{
foreach ($_POST as $key => $value) {
//For debugging - prints every iteration of the form posted data
echo "<pre>" . print_r($_POST, 1) . "</pre>";
echo "$total";
}
}
This prints the same data 6 times; like here:
Array
(
[prodname1] => Book
[prodprice1] => 19.99
[prodcode1] => 1
[prodname2] => CD
[prodprice2] => 19.99
[prodcode2] => 2
[submit] => Proceed to checkout
)
Array
(
[prodname1] => Book
[prodprice1] => 19.99
[prodcode1] => 1
[prodname2] => CD
[prodprice2] => 19.99
[prodcode2] => 2
[submit] => Proceed to checkout
)
AND SO ON..............
ALSO I am not sure how to transfer the $total value to the next page.
Many thanks.