Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display variables from my index.php to my invoice.php?
    text
    copied!<p>I'm trying to make a page so that when a user selects a quantity of any comic book and presses <code>submit</code>, it will bring them to an invoice page that will show them what comic they have selected, the quantity, and the price. </p> <p>I've tried referring from my invoice using <code>$_POST[]</code> but since I'm new to php I don't know if I'm using it right.As always, any help would be greatly appreciated.</p> <p>Here is my code (<code>index.php</code>)</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action= "invoice.php" method="post"&gt; &lt;?php /*INSERT NAME HERE This code will allow the user to purchase whatever quantity of certain comic books they want. */ $productImage = array('spiderman1.jpg', 'spiderman2.jpg', 'spiderman3.jpg', 'spiderman4.jpg', 'hulk1.jpg'); // I'm stil lhaving a hard time with multidimensional arrays. //the product image array gave me a hard time, in the sense that I'm still having a hard time trying to output an image that saves onto my desktop locally. So I chose the option of grabbing the links fromt the web. Don't worry though, I won't do this for my Assignment #1. UPDATE: Problem has been fixed! $description = array('Amazing Spiderman #1', 'Amazing Spiderman #15', 'Amazing Spiderman #52', 'Amazing Spiderman #107', 'Hulk #181'); $price = array('400', '350', '150', '300', '90'); /* For this code, credit goes to Kristen, she showed me how to loop the quantity. */ for($number = 0; $number &lt; count($allitems); $number++) { $quantity="&lt;select name='Quantity$number'&gt; &lt;option value='0'&gt;0&lt;/option&gt; &lt;option value='1'&gt;1&lt;/option&gt; &lt;option value='2'&gt;2&lt;/option&gt; &lt;option value='3'&gt;3&lt;/option&gt; &lt;/select&gt;"; } $quantity="&lt;select name='Quantity$number'&gt; &lt;option value='0'&gt;0&lt;/option&gt; &lt;option value='1'&gt;1&lt;/option&gt; &lt;option value='2'&gt;2&lt;/option&gt; &lt;option value='3'&gt;3&lt;/option&gt; &lt;/select&gt;"; echo '&lt;table border="1" align="center" cellpadding="10"&gt;'; // I'm very horrible with tables, I finally figured out how to center the text within the table. echo "&lt;tr align='center'&gt; &lt;td&gt;&lt;b&gt;Product&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Price (each)&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Quantity&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;"; foreach ($productImage as $key=&gt;$display) // I used $key to represent the value to display my images via $display. If you erase the $display code it would look very nice, but output a bunch of errors. { echo "&lt;tr align='center'&gt;"; echo '&lt;td&gt;'; echo "&lt;img src='".$productImage[$key]."' width='200' height='300' align='center'&gt;"; echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $description[$key];// Description loop from the foreach() echo '&lt;/td&gt;'; echo '&lt;td&gt;'; printf('$%', $price); // for some reason if I wanted the price to be $400.00 with '$%.2f', it would print as 1.00400. So I just kept it as whole numbers swapmeet style. echo $price[$key]; // This loops the price via the foreach() function. echo '&lt;/td&gt;'; echo '&lt;td&gt;'; echo $quantity; echo '&lt;/td&gt;'; } echo '&lt;tr&gt;'; echo '&lt;td&gt;'; echo '&lt;td&gt;'; echo '&lt;td&gt;'; echo '&lt;td&gt;'; echo 'Add to cart '; // letting the user know what to do after they picked the quantity echo '&lt;input type="submit" value="submit" name="submit"&gt;'; // my submit button echo '&lt;/td&gt;'; echo '&lt;/td&gt;'; echo '&lt;/td&gt;'; echo '&lt;/td&gt;'; echo '&lt;/tr&gt;'; echo '&lt;/table&gt;'; //The images under the description are linked to the websites, if the images are not shown it is due to the image being removed or renamed on the linked site (a disclaimer I borrowed from the assignment webpage.) ?&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And is my code for my <code>invoice.php</code></p> <pre><code>&lt;?php // a lot of trial and error and I finally got a code working so that everytime I pressed submit on the index.php page, it will direct me to the invoice.php page $name = $_POST['name']; $quantity = $_POST['Quantity$number']; $detail = $_POST['descriptoin']; $price = $_POST['price']; print '&lt;table width="790" height="31" border="1" cellpadding="1"&gt; &lt;td align="center" width="43%"&gt;&lt;b&gt;Product&lt;/b&gt;&lt;/td&gt; &lt;td width="11%"&gt;&lt;b&gt;Quantity&lt;/b&gt;&lt;/td&gt; &lt;td align="center" width="13%"&gt;&lt;b&gt;Price&lt;/b&gt;&lt;/td&gt; &lt;td align="center" width="54%"&gt;&lt;b&gt;Extended Price&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;'; print '&lt;tr&gt; &lt;td width="43%"&gt;'.$_POST[description].'&lt;/td&gt; &lt;td align="center" width="11%"&gt;'.$quantity.'&lt;/td&gt; &lt;td width="13%"&gt;'.$price.'&lt;/td&gt; &lt;td width="54%"&gt;$&amp;nbsp'.$cTotal.'&lt;/td&gt; &lt;/tr&gt;'; print '&lt;tr&gt; &lt;td width="43%"&gt;&lt;/td&gt; &lt;td align="center" width="11%"&gt;'.$_POST[qty].'&lt;/td&gt; &lt;td width="13%"&gt;'.$aPrice.'&lt;/td&gt; &lt;td width="54%"&gt;$&amp;nbsp'.$aTotal.'&lt;/td&gt; &lt;/tr&gt;'; print '&lt;tr&gt; &lt;td width="43%"&gt;&lt;/td&gt; &lt;td align="center" width="11%"&gt;'.$_POST[qty].'&lt;/td&gt; &lt;td width="13%"&gt;'.$pPrice.'&lt;/td&gt; &lt;td width="54%"&gt;$&amp;nbsp'.$pTotal.'&lt;/td&gt; &lt;/tr&gt;'; print '&lt;tr&gt; &lt;td width="43%"&gt;&lt;br&gt; &lt;/td&gt; &lt;td align="center" width="11%"&gt;'.$_POST[qty].'&lt;/td&gt; &lt;td width="13%"&gt;'.$sPrice.'&lt;/td&gt; &lt;td width="54%"&gt;$&amp;nbsp'.$sTotal.'&lt;/td&gt; &lt;/tr&gt;'; print '&lt;tr&gt; &lt;td width="43%"&gt;&lt;br&gt; &lt;/td&gt; &lt;td align="center" width="11%"&gt;'.$_POST[qty].'&lt;/td&gt; &lt;td width="13%"&gt;'.$tPrice.'&lt;/td&gt; &lt;td width="54%"&gt;$&amp;nbsp'.$tTotal.'&lt;/td&gt; &lt;/tr&gt;'; print '&lt;tr&gt; &lt;td colspan="4" width="100%"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" width="67%"&gt;Sub-total&lt;/td&gt; &lt;td width="54%"&gt;$&amp;nbsp'.$subTotal.'&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" width="67%"&gt; &lt;font face="arial"&gt; Tax @ 5.75%&lt;/font&gt;&lt;/td&gt; &lt;td width="54%"&gt;$&amp;nbsp;'.$tax.'&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" width="67%"&gt; &lt;font face="arial"&gt; Shipping &lt;/font&gt;&lt;/td&gt; &lt;td width="54%"&gt;FREE&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" width="67%"&gt;&lt;b&gt;Total&lt;/b&gt;&lt;/td&gt; &lt;td width="54%"&gt;&lt;b&gt;$&amp;nbsp;'.$Total.'&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;'; ?&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