title: Saving Dynamically Generated PHP Calculations to A MySQL Database
body: <p>I have a page with with the following php code: </p>
  
  <pre><code>&lt;?php                         
   include ('dbconnect.php');  
  
  // get values from the form
    function getPosts()
      {
       $posts = array();
       $posts[0] = $_POST['bookingid'];
       $posts[1] = $_POST['bookingname'];
       $posts[2] = $_POST['cabintype'];
       $posts[3] = $_POST['lengthofstay'];
       $posts[4] = $_POST['guests_description'];       
       $posts[5] = $_POST['startdate'];
       $posts[6] = $_POST['enddate'];
       $posts[7] = $_POST['other_information'];
       return $posts;
      } 
  
   if (isset($_POST['bookingdetails'])) {  
  
   $data = getPosts();
  
    $insert_Query = "insert into bookings(Bookingid,Bookingname,Cabin_Type,
    lengthofstay,Details_about_guests,Booking_start_date,Booking_end_date,
    Other_relavant_information)
    values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]',
           '$data[6]','$data[7]')";
  
    $result = mysqli_query($db, $insert_Query);
  
   if ($result){
     echo "&lt;p&gt;Total price is \$$total&lt;/p&gt;\n";
     Booked&lt;/p&gt; &lt;/font&gt;";
   }else{
    echo "&lt;p&gt; Something went Wrong! Contact Your Administrator &lt;/p&gt;" . 
    mysqli_error ($db);
   }
  }
  
  $Luxury_Cabin= 1200;
  $Contemporary_Cabin= 1000;
  $Original_Cabin= 800;
  $Total= "";
  
  if(isset($_POST['bookingdetails']) &amp;&amp; $_POST['luxurycabin']=='1')
  {
  $num=(int)$_POST['lengthofstay']; 
  if($num&gt;=0) 
   {
    $Total=($Luxury_Cabin*$num);
   }
  }
  
  if(isset($_POST['bookingdetails']) &amp;&amp; $_POST['contemporarycabin']=='2')
  {
  $num=(int)$_POST['lengthofstay']; 
  if($num&gt;=0) 
   {
      $Total=($Contemporary_Cabin*$num);
   }
  }
  
  if(isset($_POST['bookingdetails']) &amp;&amp; $_POST['originalcabin']=='4')
  {
  $num=(int)$_POST['lengthofstay']; 
  if($num&gt;=0)
  {
    $Total=($Original_Cabin*$num);
   }
  }
  
  echo "&lt;p&gt;Total price is \$$total&lt;/p&gt;\n";
  ?&gt;
  </code></pre>
  
  <p>And the HTML Code is like the following: </p>
  
  <pre><code>&lt;form method = "post" action = "" &gt; 
  
    &lt;tr&gt;
     &lt;th&gt;Bookingid &lt;/th&gt;
     &lt;td&gt;&lt;input type = "text" name = "bookingid" /&gt; &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
     &lt;th&gt;Booking Name &lt;/th&gt;
     &lt;td&gt;&lt;input type = "text" name = "bookingname" /&gt; &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
     &lt;th&gt;Cabin Type &lt;/th&gt;
     &lt;td&gt;&lt;input type = "text" name = "cabintype" /&gt; &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
     &lt;th&gt;Luxury Cabin&lt;/th&gt;
     &lt;td&gt;&lt;input  type="radio" name="luxurycabin" value="1" /&gt;Yes&lt;/td&gt;
     &lt;td&gt;&lt;input  type="radio" name="luxurycabin" value="0" 
     checked="checked"/&gt;No&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
     &lt;th&gt;Contemporary Cabin&lt;/th&gt;
     &lt;td&gt;&lt;input  type="radio" name="contemporarycabin" value="2" /&gt;Yes&lt;/td&gt;
     &lt;td&gt;&lt;input  type="radio" name="contemporarycabin" value="3" 
     checked="checked"/&gt;No&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
     &lt;th&gt;Original Cabin&lt;/th&gt;
     &lt;td&gt;&lt;input  type="radio" name="originalcabin" value="4" /&gt;Yes&lt;/td&gt;
     &lt;td&gt;&lt;input  type="radio" name="originalcabin" value="5" 
      checked="checked"/&gt;No&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;th&gt;Length of Stay &lt;/th&gt;
      &lt;td&gt;&lt;input type = "text" name = "lengthofstay" id="lengthofstay"/&gt; &lt;/td&gt;
      &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;th&gt;Details About Guests &lt;/th&gt;
      &lt;td&gt;&lt;textarea cols = "30" rows = "5" type = "text" name 
      ="guests_description" /&gt;&lt;/textarea&gt; &lt;/td&gt;
    &lt;/tr&gt; 
  
    &lt;tr&gt;
      &lt;th&gt;Booking Start Date &lt;/th&gt;
      &lt;td&gt;&lt;input type = "text" name = "startdate" /&gt; &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;th&gt;Booking End Date &lt;/th&gt;
      &lt;td&gt;&lt;input type = "text" name = "enddate" /&gt; &lt;/td&gt;
    &lt;/tr&gt; 
  
    &lt;tr&gt;
     &lt;th&gt;Other Relavant Information &lt;/th&gt;
     &lt;td&gt;&lt;textarea cols = "30" rows = "5" type = "text" name 
     ="other_information" /&gt;&lt;/textarea&gt; &lt;/td&gt;
    &lt;/tr&gt;          
  
     &lt;tr&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;td&gt; &lt;input type = "submit" value = "Create Booking!" name = 
        "bookingdetails" /&gt; &lt;/td&gt;
     &lt;/tr&gt; 
  
  &lt;/table&gt;             
  &lt;/form&gt;
  </code></pre>
  
  <p>What occurs here is that when the "bookingdetails" button is pressed all of the data entered into the form are sent to the database. What is also done is a multiplication calculation which uses the radio buttons and the number entered into the lenghtofstay field. The result is then echoed on the page itself using: </p>
  
  <pre><code>&lt;?php echo "&lt;p&gt;Total price is \£$total&lt;/p&gt;\n"; ?&gt; 
  </code></pre>
  
  <p>So what I need your assistance with is how do I get the dynamically generated calculation result into my database table with a column called Booking_Price?   </p>