Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to properly transfer user input from index to invoice?
    text
    copied!<p>I got a dillema, I'm trying to find a solution for my code. How do I make it so that when the user inputs a given quantity in the text box from the index.php it will transfer that input quantity to the invoice.php. I've tried doing the post method but it seems like it's not working :/ As always, any help or suggestions will be greatly appreciated! I hope it's something simple:( Here's my code:</p> <p>This code holds my products array and also includes my text box. <pre><code>//The following arrays contain our products and their information, one product per array. $hulkhamburger = array('Product' =&gt; 'Hulk Hamburger', 'Description' =&gt; '...', 'Price' =&gt; '$1.00', 'Quantity' =&gt; "&lt;input type='text' name='quantity1'&gt;"); $atomichotdog = array('Product' =&gt; 'Atomic Hot Dog', 'Description' =&gt; '...', 'Price' =&gt; '$2.00', 'Quantity' =&gt; "&lt;input type='text' name='quantity2'&gt;"); $friedchicken = array('Product' =&gt; 'Fantastic 4 Fried Chicken', 'Description' =&gt; '...', 'Price' =&gt; '$3.00', 'Quantity' =&gt; "&lt;input type='text' name='quantity3'&gt;"); $psyonicpizza = array('Product' =&gt; 'Psyonic Pizza', 'Description' =&gt; '...', 'Price' =&gt; '$4.00', 'Quantity' =&gt; "&lt;input type='text' name='quantity4'&gt;"); $marvelmeatloaf = array('Product' =&gt; 'Marvel Meatloaf', 'Description' =&gt; '...', 'Price' =&gt; '$5.00', 'Quantity' =&gt; "&lt;input type='text' name='quantity5'&gt;"); //The following array takes our previous five arrays and puts them into one array for easier coding and reading. $allfood = array ($hulkhamburger, $atomichotdog, $friedchicken, $psyonicpizza, $marvelmeatloaf); ?&gt; </code></pre> <p>index.php</p> <pre><code>&lt;html&gt; &lt;style&gt; body{ background-image: url('URL HERE'); font-family: "Helvetica"; font-size:15px; } h1{ color:black; text-align:center; } p{ font-size:15px; } &lt;/style&gt; &lt;h1&gt; STORE TITLE HERE &lt;/h1&gt; &lt;body&gt; &lt;form action="login.php" method="post"&gt; &lt;?php //Include products info.inc (Which holds all our product arrays and info) //Credit: Tracy &amp; Mark (THank you!) include 'products_info.inc'; /*The following code centers my table on the page, makes the table background white, makes the table 50% of the browser window, gives it a border of 1 px, gives a padding of 2 px between the cell border and content, and gives 1 px of spacing between cells. */ echo "&lt;table align=center bgcolor='FFFFFF' width=50% border=1 cellpadding=1 cellspacing=2&gt;"; //Credit: Tracy &amp; Mark (THank you!) echo '&lt;th&gt;Product&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;th&gt;Price&lt;/th&gt; &lt;th&gt;Quantity&lt;/th&gt;'; //The following code loops through the whole table body and then prints each row. for($i=0; $i&lt;count($allfood); $i++) { //Credit: Tracy &amp; Mark (THank you!) echo "&lt;tr align=center&gt;"; echo "&lt;td&gt;{$allfood[$i]['Product']}&lt;/td&gt;"; echo "&lt;td&gt;{$allfood[$i]['Description']}&lt;/td&gt;"; echo "&lt;td&gt;{$allfood[$i]['Price']}&lt;/td&gt;"; echo "&lt;td&gt;{$allfood[$i]['Quantity']}&lt;/td&gt;"; echo "&lt;/tr&gt;"; } //This code ends the table. echo "&lt;/table&gt;"; echo "&lt;br&gt;"; ?&gt; &lt;br&gt;&lt;center&gt;&lt;input type='submit' name='purchase' value='Purchase'&gt;&lt;/center&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here's my invoice.php</p> <pre><code>&lt;html&gt; &lt;style&gt; body{ background-image: url('URL HERE'); font-family: "Helvetica"; font-size:15px; } h1{ color:black; text-align:center; } p{ font-size:15px; } &lt;/style&gt; &lt;h1&gt; Invoice &lt;/h1&gt; &lt;/html&gt; &lt;?php //Include products info.inc (Which holds all our product arrays and info) //Credit: Tracy &amp; Mark (Thank you!) include 'products_info.inc'; //Display the invoice &amp; 'WELCOME USER. THANK YOU FOR USING THIS DAMN THING msg' /*The following code centers my invoice table on the page, makes the table background white, makes the table 50% of the browser window, gives it a border of 1 px, gives a padding of 2 px between the cell border and content, and gives 1 px of spacing between cells. */ echo "&lt;table align=center bgcolor='FFFFFF' width=50% border=1 cellpadding=1cellspacing=2&gt;"; echo "&lt;tr&gt;"; echo "&lt;td align=center&gt;&lt;b&gt;Product&lt;/b&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;b&gt;Quantity&lt;/b&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;b&gt;Price&lt;/&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;b&gt;Extended Price&lt;/b&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;"; for($i=0; $i&lt;count($allfood); $i++) { //Credit: Tracy &amp; Mark (Thank you!) $qty= @$_POST['Quantity']['$i']; // This calculates the price if the user orders more than 1 item. $extendedprice = $qty*$allfood[$i]['Price']; echo "&lt;tr&gt;"; echo "&lt;td align=center&gt;{$allfood[$i]['Product']}&lt;/td&gt;"; echo "&lt;td align=center&gt;$extendedprice&lt;/td&gt;"; echo "&lt;td align=center&gt;{$allfood[$i]['Price']}&lt;/td&gt;"; echo "&lt;/tr&gt;"; } // The goal here was to make it so that if the user selected a certain quantity from index.php, it would carry over and display on the invoice.php if ($qty = 0) { echo "please choose 1"; } elseif ($qty &gt; 0) { echo $qty; } /*echo "&lt;tr&gt;"; echo "&lt;td align=center&gt;Subtotal&lt;/b&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;/td&gt;"; echo "&lt;tr&gt;"; echo "&lt;td align=center&gt;Tax at 5.75%&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;/td&gt;"; echo "&lt;tr&gt;"; echo "&lt;td align=center&gt;&lt;b&gt;Grand total&lt;/b&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;/td&gt;"; echo "&lt;td align=center&gt;&lt;/td&gt;"; */ echo "&lt;/table&gt;"; ?&gt; &lt;br&gt; &lt;center&gt; &lt;form action="index.php" method="post"&gt; &lt;input type="submit" name="home" value="Back to homepage"&gt; &lt;/form&gt; &lt;/center&gt; </code></pre>
 

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