title: inserting data into mysql database using php
body: <p>I have a php order form named (order.php) and when the user clicks the (submit button "Next Step") it takes him to another page called (confirm-order.php)</p>
  
  <p>The (confirm-order.php) shows the information that the user submitted from the (order.php) using the $_POST[] and by assigning each one of these to a variable.</p>
  
  <p>Data showing on the (confirm-order.php) plain text like for example :</p>
  
  <pre><code>$itemName = $_POST['itemName'];
  &lt;?php echo $itemName; ?&gt;
  </code></pre>
  
  <p>at the end of page there is a form contains only one element as (submit button)</p>
  
  <p>How can i insert the $itemName data into mysql database only (after the submit button is clicked and the form actions take me to the confirmation page)?</p>
  
  <p>I know how to insert data into mysql, but it didn't work with the isset() function</p>
  
  <p>Do i have to write the isset function inside the form first? and below it the mysql database code?</p>
  
  <p>order.php page:</p>
  
  <pre><code>&lt;form class="form-horizontal well" action="confirm-order.php" method="POST"&gt;
      &lt;fieldset&gt;
        &lt;legend&gt;Personal Shopper Order Form&lt;/legend&gt;
        &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="select01"&gt;Choose a plan&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;select id="select01" name="plan"&gt;
              &lt;option&gt;Lite Plan $0 per order&lt;/option&gt;
            &lt;/select&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="itemName"&gt;Item Name&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;input type="text" class="input-xlarge" id="itemName" name="itemName"&gt;
            &lt;p class="help-block"&gt;Item name exapmle: iPad3 White 32GB wifi &amp; 3G.&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
         &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="itemID"&gt;Item ID&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;input type="text" class="input-xlarge" id="itemID" name="itemID"&gt;
            &lt;p class="help-block"&gt;example: Ebay Item ID, Amazon Item ID.&lt;/p&gt;
          &lt;/div&gt;&lt;br&gt;
          &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="itemURL"&gt;Item URL&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;input type="text" class="input-xxlarge" id="itemURL" name="itemURL"&gt;
            &lt;p class="help-block"&gt;Direct web link to the item.&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="textarea"&gt;Item Details&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;textarea class="input-xlarge" id="textarea" name="itemDetails" rows="6"&gt;&lt;/textarea&gt;
            &lt;p class="help-block"&gt;Item details (name, color, specifications etc...)&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;li id="li_3" data-pricefield="money_simple" data-pricevalue="0"&gt;
         &lt;div class="input-prepend input-append"&gt;
          &lt;label class="control-label" for="element_3_1"&gt;Item Price&lt;/label&gt;
          &lt;div class="controls"&gt;
          &lt;span class="add-on"&gt;$&lt;/span&gt;
            &lt;input id="element_3_1" data-price-value="10.00"  name="element_3" type="text" class="element text large"&gt;
            &lt;p class="help-block"&gt;Item exact price on the US online store.&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
       &lt;/li&gt;
       &lt;li id="li_7" data-pricefield="money_simple" data-pricevalue="0"&gt;
         &lt;div class="input-prepend input-append"&gt;
          &lt;label class="control-label" for="element_7_1"&gt;Local Shipping Cost&lt;/label&gt;
          &lt;div class="controls"&gt;
          &lt;span class="add-on"&gt;$&lt;/span&gt;
            &lt;input id="element_7_1" data-price-value="10.00"  name="element_7" type="text" class="element text large"&gt;
          &lt;/div&gt;
          &lt;p class="help-block"&gt;Local shipping fee from the US Store to Sky2ship (if applicable).&lt;/p&gt;
        &lt;/div&gt;
       &lt;/li&gt;
       &lt;li id="li_8" data-pricefield="radio" data-pricevalue="0"&gt;
       &lt;div class="control-group"&gt;
        &lt;div class="controls"&gt;
        &lt;p class="help-block"&gt;Order Processing Service Fee.&lt;/p&gt;
          &lt;label class="radio"&gt;($0) Standard 2-3 days
          &lt;input id="element_8_1" data-pricedef="00.00" name="element_8" class="element radio" type="radio" value="$0 Standard 2-3 Day"&gt;
          &lt;/label&gt;
          &lt;label class="radio"&gt;($10) Express 1 day
          &lt;input id="element_8_2" data-pricedef="10.00" name="element_8" class="element radio" type="radio" value="$10 Express Same Day"&gt;
  
          &lt;/label&gt;
        &lt;/div&gt;
        &lt;/div&gt;
        &lt;/li&gt;
        &lt;legend&gt;Personal Information &amp; Shipping Address&lt;/legend&gt;
       &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="input04"&gt;Full Name&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;input type="text" class="input-medium" id="fullName" name="fullName"&gt;
            &lt;p class="help-block"&gt;First &amp; last name.&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="control-group"&gt;
        &lt;div class="controls"&gt;
          &lt;label class="radio"&gt;Male
          &lt;input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked&gt;
          &lt;/label&gt;
          &lt;label class="radio"&gt;
          &lt;input type="radio" name="optionsRadios" id="optionsRadios2" value="option2"&gt;Female
  
          &lt;/label&gt;
        &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="input-prepend"&gt;
          &lt;label class="control-label" for="prependedInput"&gt;Email Address&lt;/label&gt;
          &lt;div class="controls"&gt;
          &lt;span class="add-on"&gt;@&lt;/span&gt;
            &lt;input type="text" class="span2" id="prependedInput" name="Email"&gt;
            &lt;p class="help-block"&gt;Your email address.&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="input06"&gt;Address&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;input type="text" class="input-xxlarge" id="input06" name="streetAddress" placeholder="Street Address"&gt;
            &lt;p class="help-block"&gt;Your shipping address.&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
         &lt;div class="control-group"&gt;
          &lt;div class="controls controls-row"&gt;
            &lt;input type="text" class="span2" id="City" name="City" placeholder="City"&gt;
            &lt;input type="text" class="span3" id="State" name="State" placeholder="State / Province"&gt;
  
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="control-group"&gt;
          &lt;div class="controls controls-row"&gt;
            &lt;input type="text" class="span2" id="PostalCode" name="PostalCode" placeholder="Postal Code"&gt;
            &lt;input type="text" class="span3" id="Phone" name="Phone" placeholder="Phone Number"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="select01"&gt;Country&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;select id="select02" name="Country"&gt;
              &lt;option&gt;IRAQ&lt;/option&gt;
              &lt;option&gt;JORDON&lt;/option&gt;
            &lt;/select&gt;
          &lt;/div&gt;
        &lt;/div&gt;
         &lt;li class="total_payment" align="right" data-basetotal="0"&gt;
  
              &lt;span&gt;
  
                  &lt;h3 class="alert-success"&gt;&amp;#36;&lt;var&gt;0&lt;/var&gt;&lt;/h3&gt;
  
                  &lt;h5&gt;Total&lt;/h5&gt;
  
              &lt;/span&gt;
  
          &lt;/li&gt;   
        &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="optionsCheckbox"&gt;Read &amp; Agree&lt;/label&gt;
          &lt;div class="controls"&gt;
            &lt;label class="checkbox"&gt;
              &lt;input type="checkbox" id="optionsCheckbox" value="option1"&gt;
              &lt;a href="#"&gt;I agree to the site's Terms of Service &amp; Privacy Policy.&lt;/a&gt;
            &lt;/label&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div class="form-actions"&gt;
          &lt;button type="submit" class="btn btn-primary"&gt;Confirm Order&lt;/button&gt;
          &lt;button type="reset" class="btn"&gt;Cancel Order&lt;/button&gt;
        &lt;/div&gt;
      &lt;/fieldset&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>confirm-order.php page:</p>
  
  <pre><code>    &lt;?php
  
  $itemName = $_POST['itemName'];
  $plan = $_POST['plan'];
  $itemID = $_POST['itemID'];
  $itemPrice = $_POST['element_3'];
  $processService = $_POST['element_8'];
  $itemDetails = $_POST['itemDetails'];
  $streetAddress = $_POST['streetAddress'];
  $City = $_POST['City'];
  $State = $_POST['State'];
  $PostalCode = $_POST['PostalCode'];
  $Phone = $_POST['Phone'];
  $Country = $_POST['Country'];
  $fullName = $_POST['fullName'];
  $Email = $_POST['Email'];
  $itemURL = $_POST['itemURL'];
  $itemLocalShipCost = $_POST['element_7'];
  
  ?&gt;
  
  
   &lt;?php
  $db_host = "localhost";
  $db_user = "root";
  $db_pass = "000000";
  $db_name = "dbname";
      if (isset($_POST['submit'])) {
    $db_connect = mysqli_connect($db_host,$db_user,$db_pass,$db_name);
    // Check connection
           if (mysqli_connect_errno())
    {
           echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
    $sql ="INSERT INTO lite_order (lite_plan, lite_item_name)
          VALUES
    ('$plan','$item')";
  
            if (!mysqli_query($db_connect,$sql))
    {
            die('Error: ' . mysqli_error($db_connect));
    }
            echo "1 record added";
      }
  
  
  ?&gt;
  &lt;address&gt;
                &lt;strong&gt;Shipping Address.&lt;/strong&gt;&lt;br&gt;
                &lt;?php echo $streetAddress; ?&gt;&lt;br&gt;
                &lt;?php echo $City; ?&gt;, &lt;?php echo $State; ?&gt;, &lt;?php echo $PostalCode; ?&gt;&lt;br&gt;&lt;?php echo $Country; ?&gt;&lt;br&gt;
                &lt;abbr title="Phone"&gt;P:&lt;/abbr&gt;&lt;?php echo $Phone; ?&gt;
              &lt;/address&gt;
              &lt;address&gt;
                &lt;strong&gt;&lt;?php echo $fullName; ?&gt;&lt;/strong&gt;&lt;br&gt;
                &lt;a href="mailto:#"&gt;&lt;?php echo $Email; ?&gt;&lt;/a&gt;
              &lt;/address&gt;
  
              &lt;table class="table"&gt;
                &lt;thead&gt;
                  &lt;tr&gt;
                    &lt;th&gt;Plan&lt;/th&gt;
                    &lt;th&gt;Item Name&lt;/th&gt;
                    &lt;th&gt;Item ID&lt;/th&gt;
                    &lt;th&gt;Local Shipping Cost&lt;/th&gt;
                    &lt;th&gt;Item Price&lt;/th&gt;
                    &lt;th&gt;Order Processing Fee&lt;/th&gt;
                  &lt;/tr&gt;
                &lt;/thead&gt;
                &lt;tbody&gt;
                  &lt;tr class="success"&gt;
                    &lt;td&gt;&lt;?php echo $plan; ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $itemName; ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $itemID; ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo "$" . $itemLocalShipCost; ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo "$" . $itemPrice; ?&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $processService; ?&gt;&lt;/td
                  &gt;&lt;/tr&gt;
                &lt;/tbody&gt;
              &lt;/table&gt;
              &lt;strong&gt;Item URL&lt;/strong&gt;&lt;p class="alert alert-info"&gt;&lt;?php echo $itemURL; ?&gt;&lt;/p&gt;
              &lt;pre class="pre-scrollable"&gt;&lt;?php echo $itemDetails; ?&gt;&lt;/pre&gt;
              &lt;p&gt;Your Total &lt;h3 class="question"&gt;&lt;?php echo "$" . $orderTotal; ?&gt;&lt;/h3&gt;&lt;/p&gt;
                           &lt;div class="form-actions"&gt;&lt;form action="pending-order.php" method="post" name="confirmed-order"&gt;
                            &lt;button type="submit" name="submit" class="btn btn-primary"&gt;Submit Order&lt;/button&gt;
                            &lt;button type="button" class="btn"&gt;Previous&lt;/button&gt;&lt;/form&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Whereto insert the mysql database code to insert all the variables into database after the submit button is clicked? where to place the isset() function? i tried it, it didn't insert any data into my table.</p>