Passing a variable from a HTML file with Javascript to a PHP file
<p>I have this assignment where I'm supposed to make a form using HTML &amp; Javascript, then pass the variables to a PHP file later on using POST.</p>

<p>My teacher gave us this sample code to follow (link below), but upon testing it doesn't work at all and none of the variables get passed! Can anyone help me look at the .PHP file and see why it doesn't seem to work at all?</p>

<p>All help would be appreciated, thanks.</p>

<p>HTML: </p>

<pre><code>&lt;?xml version = "1.0"  encoding = "utf-8" ?&gt;
&lt;!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN"

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;



&lt;!-- popcorn3.html 
     This describes the popcorn sales form
     --&gt;

&lt;html xmlns = "http://www.w3.org/1999/xhtml"&gt;

  &lt;head&gt;

&lt;title&gt; Popcorn Sales - for PHP handling &lt;/title&gt;

&lt;/head&gt;
  &lt;body&gt;
    &lt;form action = "popcorn3.php"
          method = "post"&gt;
      &lt;h2&gt; Welcome to Millennium Gymnastics Booster Club Popcorn
           Sales &lt;/h2&gt;
      &lt;table&gt;

&lt;!-- Text widgets for the customer's name and address --&gt;
    &lt;tr&gt;
      &lt;td&gt; Buyer's Name: &lt;/td&gt;
      &lt;td&gt; &lt;input type = "text"  name = "name" 

              size = "30" /&gt;
          &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt; Street Address: &lt;/td&gt;
      &lt;td&gt; &lt;input type = "text"  name = "street" 
              size = "30" /&gt;
          &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
          &lt;td&gt; City, State, Zip: &lt;/td&gt;
      &lt;td&gt; &lt;input type = "text"  name = "city"

              size = "30" /&gt;
          &lt;/td&gt;
    &lt;/tr&gt;
      &lt;/table&gt;
      &lt;p /&gt;
      &lt;table border = "border"&gt;

&lt;!-- First, the column headings --&gt;
    &lt;tr&gt;
      &lt;th&gt; Product &lt;/th&gt;
      &lt;th&gt; Price &lt;/th&gt;
      &lt;th&gt; Quantity &lt;/th&gt;
    &lt;/tr&gt;

&lt;!-- Now, the table data entries --&gt;
    &lt;tr&gt;
      &lt;td&gt; Unpopped Popcorn (1 lb.) &lt;/td&gt;
      &lt;td&gt; $3.00 &lt;/td&gt;
          &lt;td align = "center"&gt;
        &lt;input type = "text"  name = "unpop"
           size = "3" /&gt;
          &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;

      &lt;td&gt; Caramel Popcorn (2 lb. canister) &lt;/td&gt;
      &lt;td&gt; $3.50 &lt;/td&gt;
          &lt;td align = "center"&gt;
        &lt;input type = "text"  name = "caramel"
           size = "3" /&gt; 
          &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;

      &lt;td&gt; Caramel Nut Popcorn (2 lb. canister) &lt;/td&gt;
      &lt;td&gt; $4.50 &lt;/td&gt;

      &lt;td align = "center"&gt;
        &lt;input type = "text"  name = "caramelnut"
           size = "3" /&gt;
          &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
          &lt;td&gt; Toffey Nut Popcorn (2 lb. canister) &lt;/td&gt;
          &lt;td&gt; $5.00 &lt;/td&gt;
          &lt;td align = "center"&gt;
        &lt;input type = "text"  name = "toffeynut"
           size = "3" /&gt;
          &lt;/td&gt;
    &lt;/tr&gt;
      &lt;/table&gt;
      &lt;p /&gt;

&lt;!-- The radio buttons for the payment method --&gt;
      &lt;h3&gt; Payment Method &lt;/h3&gt;
      &lt;p&gt;
        &lt;input type = "radio"  name = "payment"  value = "visa" 

               checked = "checked" /&gt; 
        Visa &lt;br /&gt;
        &lt;input type = "radio"  name = "payment"  value = "mc" /&gt;

        Master Card &lt;br /&gt;
        &lt;input type = "radio"  name = "payment"  value = "discover" /&gt;
        Discover &lt;br /&gt;
        &lt;input type = "radio"  name = "payment"  value = "check" /&gt; 
        Check &lt;br /&gt; &lt;br /&gt;

&lt;!-- The submit and reset buttons --&gt;
        &lt;input type = "submit"  value = "Submit Order" /&gt;
        &lt;input type = "reset"  value = "Clear Order Form" /&gt;

      &lt;/p&gt;

    &lt;/form&gt;

  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>PHP: </p>

<pre><code>&lt;?xml version = "1.0"  encoding = "utf-8" ?&gt;
&lt;!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

&lt;!-- popcorn3.php - Processes the form described in
     popcorn3.html
     --&gt;
&lt;html xmlns = "http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
    &lt;title&gt; Process the popcorn3.html form &lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;?php

// Get form data values

      $unpop = $_POST["unpop"];
      $caramel = $_POST["caramel"];
      $caramelnut = $_POST["caramelnut"];
      $toffeynut = $_POST["toffeynut"];
      $name = $_POST["name"];
      $street = $_POST["street"];
      $city = $_POST["city"];
      $payment = $_POST["payment"];

// If any of the quantities are blank, set them to zero

      if ($unpop == "") $unpop = 0;
      if ($caramel == "") $caramel = 0;
      if ($caramelnut == "") $caramelnut = 0;
      if ($toffeynut == "") $toffeynut = 0;

// Compute the item costs and total cost

      $unpop_cost = 3.0 * $unpop;
      $caramel_cost = 3.5 * $caramel;
      $caramelnut_cost = 4.5 * $caramelnut;
      $toffeynut_cost = 5.0 * $toffeynut;
      $total_price = $unpop_cost + $caramel_cost + 
                     $caramelnut_cost + $toffeynut_cost;
      $total_items = $unpop + $caramel + $caramelnut + $toffeynut;

// Return the results to the browser in a table

    ?&gt;
    &lt;h4&gt; Customer: &lt;/h4&gt;
    &lt;?php
      print ("$name &lt;br /&gt; $street &lt;br /&gt; $city &lt;br /&gt;");
    ?&gt;
    &lt;p /&gt; &lt;p /&gt;

    &lt;table border = "border"&gt;
      &lt;caption&gt; Order Information &lt;/caption&gt;
      &lt;tr&gt;
        &lt;th&gt; Product &lt;/th&gt;
        &lt;th&gt; Unit Price &lt;/th&gt;
        &lt;th&gt; Quantity Ordered &lt;/th&gt;
        &lt;th&gt; Item Cost &lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr align = "center"&gt;
        &lt;td&gt; Unpopped Popcorn &lt;/td&gt;
        &lt;td&gt; $3.00 &lt;/td&gt;
        &lt;td&gt; &lt;?php print ("$unpop"); ?&gt; &lt;/td&gt;
        &lt;td&gt; &lt;?php printf ("$ %4.2f", $unpop_cost); ?&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr align = "center"&gt;
        &lt;td&gt; Caramel Popcorn &lt;/td&gt;
        &lt;td&gt; $3.50 &lt;/td&gt;
        &lt;td&gt; &lt;?php print ("$caramel"); ?&gt; &lt;/td&gt;
        &lt;td&gt; &lt;?php printf ("$ %4.2f", $caramel_cost); ?&gt;
        &lt;/td&gt;
        &lt;/tr&gt;
      &lt;tr align = "center"&gt;
        &lt;td&gt; Caramel Nut Popcorn &lt;/td&gt;
        &lt;td&gt; $4.50 &lt;/td&gt;
        &lt;td&gt; &lt;?php print ("$caramelnut"); ?&gt; &lt;/td&gt;
        &lt;td&gt; &lt;?php printf ("$ %4.2f", $caramelnut_cost); ?&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr align = "center"&gt;
        &lt;td&gt; Toffey Nut Popcorn &lt;/td&gt;
        &lt;td&gt; $5.00 &lt;/td&gt;
        &lt;td&gt; &lt;?php print ("$toffeynut"); ?&gt; &lt;/td&gt;
        &lt;td&gt; &lt;?php printf ("$ %4.2f", $toffeynut_cost); ?&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
    &lt;p /&gt; &lt;p /&gt;

    &lt;?php
      print ("You ordered $total_items popcorn items &lt;br /&gt;");
      printf ("Your total bill is: $ %5.2f &lt;br /&gt;", $total_price);
      print ("Your chosen method of payment is: $payment &lt;br /&gt;");
    ?&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
