Note that there are some explanatory texts on larger screens.

plurals
  1. POretrieve data input to a new page in php
    primarykey
    data
    text
    <p>I try to print out the data from my another page to my new page when I click submit in cart.php</p> <p>this is my code</p> <p>cart.php</p> <pre><code>function paypal_items(){ $num = 0; foreach ($_SESSION as $name =&gt; $value){ if ($value !=0){ if (substr($name, 0, 5) == "cart_"){ $id = substr ($name, 5, strlen($name)-5); $get = mysql_query ('SELECT id, name, price FROM menu WHERE id='.mysql_real_escape_string((int)$id)); while ($get_row = mysql_fetch_assoc($get)) { $num++; echo '&lt;input type="hidden" name="item_number_'.$num.'" value="'.$id.'"&gt;'; echo '&lt;input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'"&gt;'; echo '&lt;input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'"&gt;'; echo '&lt;input type="hidden" name="quantity_'.$num.'" value="'.$value.'"&gt;'; } } } } } function cart() { $total = 0; foreach($_SESSION as $name =&gt; $value) { if ($value&gt;0) { if (substr($name, 0, 5) == 'cart_'){ $id = substr($name, 5, (strlen($name)-5)); $get = mysql_query('SELECT id, name, price FROM menu WHERE id=' .mysql_real_escape_string((int)$id)); while ($get_row = mysql_fetch_assoc($get)){ $sub = $get_row['price'] * $value; $target_data = $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2); $_SESSION['target_data'] = $target_data; echo $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2).' &lt;a href="cart.php?remove='.$id.'"&gt;[-]&lt;/a&gt; &lt;a href="cart.php?add='.$id.'"&gt;[+]&lt;/a&gt; &lt;a href="cart.php?delete='.$id.'"&gt;[Delete]&lt;/a&gt;&lt;br /&gt;' ; } } $total += $sub; } } if ($total == 0){ echo "Your Cart Is Empty"; } else { echo "&lt;p&gt;Total : $".number_format($total, 2).'&lt;/p&gt;'; &lt;p&gt; &lt;form action="bill.php" method="post"&gt; &lt;?php paypal_items(); ?&gt; &lt;input type="submit" value="submit" /&gt; &lt;/form&gt; &lt;/p&gt; } } </code></pre> <p>I try to to print out this data from function cart()</p> <pre><code> echo $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2).' &lt;a href="cart.php?remove='.$id.'"&gt;[-]&lt;/a&gt; &lt;a href="cart.php?add='.$id.'"&gt;[+]&lt;/a&gt; &lt;a href="cart.php?delete='.$id.'"&gt;[Delete]&lt;/a&gt;&lt;br /&gt;' ; </code></pre> <p>with this code I try to retrieve all the data input</p> <p>bill.php</p> <pre><code>&lt;?php session_start(); echo $_SESSION['target_data'] .'&lt;br /&gt;'; print_r($_POST); ?&gt; </code></pre> <p>however the output that I got is like (I have two data to display when I click submit)</p> <pre><code> Milk Tea x 9 @ $1.99 = $17.91 Array ( [item_number_1] =&gt; 2 [item_name_1] =&gt; Ayam Penyet [amount_1] =&gt; 6.99 [quantity_1] =&gt; 8 [item_number_2] =&gt; 1 [item_name_2] =&gt; Milk Tea [amount_2] =&gt; 1.99 [quantity_2] =&gt; 9 ) </code></pre> <p>the expected output that I want is like</p> <pre><code> Milk Tea x 9 @$1.99 = $17.91 Ayam Penyet x 8 @6.99 = $55.92 </code></pre> <p>anyone know how to solve this??</p> <p>thanks :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload