Note that there are some explanatory texts on larger screens.

plurals
  1. POEasiest way to submit data via PHP?
    text
    copied!<p>I'm new to PHP, and have spent 10 hours trying to figure this problem out.</p> <p><strong>The goal</strong> is to take all data entered into this order form, and send it to my email via PHP.</p> <p><em>I have 2 questions:</em></p> <p><strong>1.</strong> I can get PHP to send data from a single menu item (example: Mexican Tortas), but how do I get PHP to send data from multiple items (example: Mexican Tortas, Fish Sandwich and Hamburger)?</p> <p><strong>2.</strong> How do I tell PHP to not send data from menu items that don't have the "How Many?" or "Customize It?" text fields filled out?</p> <p>If you could provide a super simple example (or a link to a learning resource) I would really appreciate it.</p> <p>Thank you, Abijah</p> <hr> <p><strong>PHP</strong></p> <pre><code>&lt;?php if(isset($_POST['submit'])) { $to = "test@mywebsite.com"; $subject = "New Order"; $name_field = $_POST['name']; $phone_field = $_POST['phone']; $item = $_POST['item']; $quantity = $_POST['quantity']; $customize = $_POST['customize']; } $body = "Name: $name_field\nPhone: $phone_field\n\nItem: $item\nQuantity: $quantity\nCustomize: $customize"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); ?&gt; </code></pre> <hr> <p><strong>HTML</strong></p> <pre><code>&lt;form action="neworder.php" method="POST"&gt; &lt;div class ="item"&gt; &lt;img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/mexicantortas.jpg"&gt; &lt;h1&gt;Mexican Torta - $8.50&lt;/h1&gt; &lt;input name="item" type="hidden" value="Mexican Torta"/&gt; &lt;h2&gt;How Many? &lt;font color="#999999"&gt;Ex: 1, 2, 3...?&lt;/font&gt;&lt;/h2&gt; &lt;input name="quantity" type="text"/&gt; &lt;h3&gt;Customize It? &lt;font color="#999999"&gt;Ex: No Lettuce, Extra Cheese...&lt;/font&gt;&lt;/h3&gt; &lt;textarea name="customize"/&gt;&lt;/textarea&gt; &lt;/div&gt;&lt;!-- ITEM_LEFT --&gt; &lt;div class ="item"&gt; &lt;img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/fishsandwich.jpg"&gt; &lt;h1&gt;Fish Sandwich - $8.50&lt;/h1&gt; &lt;input name="item" type="hidden" value="Fish Sandwich"/&gt; &lt;h2&gt;How Many? &lt;font color="#999999"&gt;Ex: 1, 2, 3...?&lt;/font&gt;&lt;/h2&gt; &lt;input name="quantity" type="text"/&gt; &lt;h3&gt;Customize It? &lt;font color="#999999"&gt;Ex: No Lettuce, Extra Cheese...&lt;/font&gt;&lt;/h3&gt; &lt;textarea name="customize"/&gt;&lt;/textarea&gt; &lt;/div&gt;&lt;!-- ITEM_LEFT --&gt; &lt;div class ="item"&gt; &lt;img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/hamburgers.jpg"&gt; &lt;h1&gt;Hamburger w/ Fries - $7.00&lt;/h1&gt; &lt;input name="item" type="hidden" value="Fish Sandwich"/&gt; &lt;h2&gt;How Many? &lt;font color="#999999"&gt;Ex: 1, 2, 3...?&lt;/font&gt;&lt;/h2&gt; &lt;input name="quantity" type="text"/&gt; &lt;h3&gt;Customize It? &lt;font color="#999999"&gt;Ex: No Lettuce, Extra Cheese...&lt;/font&gt;&lt;/h3&gt; &lt;textarea name="customize"/&gt;&lt;/textarea&gt; &lt;/div&gt;&lt;!-- ITEM_LEFT --&gt; &lt;div class="horizontal_form"&gt; &lt;div class="form"&gt; &lt;h2&gt;Place Your Order Now: &lt;font size="3"&gt;&lt;font color="#037B41"&gt;Fill in the form below, and we'll call you when your food is ready to be picked up...&lt;/font&gt;&lt;/font&gt;&lt;/h2&gt; &lt;p class="name"&gt; &lt;input type="text" name="name" id="name" style="text-align:center;" onClick="this.value='';" value="Enter your name"/&gt; &lt;/p&gt; &lt;p class="phone"&gt; &lt;input type="text" name="phone" id="phone" style="text-align:center;" onClick="this.value='';" value="Enter your phone #"/&gt; &lt;/p&gt; &lt;p class="submit"&gt; &lt;input type="submit" value="Place Order" name="submit"/&gt; &lt;/p&gt; &lt;/div&gt;&lt;!-- FORM --&gt; &lt;/div&gt;&lt;!-- HORIZONTAL_FORM --&gt; &lt;/form&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