title: Unable to insert data to database using PhP inside the modal
body: <p>This modal once submitted will insert all the data to my database, but I'm having difficulty figuring out how to work it out. As you can see once I clicked the button for "save changes" nothing works. I tried checking my database to see if something has been inserted but to no avail there's none. Can someone help me. Thanks.</p>
  
  <pre><code>&lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
    &lt;div class="modal-dialog "&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header" id="bg"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
          &lt;h4 class="modal-title" &gt;Sign Up&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body" id="bg"&gt;
  
        &lt;?php
        require('config/db_conn.php');
        if(isset($_POST['save']))
        {
           $fname=$_POST['firstName'];
           $lname=$_POST['lastName'];
           $add= $_POST['address'];
           $cont=$_POST['contact'];
           $user=$_POST['userName'];
           $pass=$_POST['paasWord'];
           $type=$_POST['selectType'];
  
           mysql_query("INSERT INTO customer (c_fname,c_lname,c_address,c_con,c_user,c_pass,c_type) VALUES ('$fname','$lname','$add','$cont','$user','$pass','$type')") or die(mysql_error());
  
              header("location: login.php");
  
        }
        ?&gt;
  
          &lt;form method="post" action=""&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="exampleInputFirstName"&gt;First Name&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="exampleInputFirstName" placeholder="Username" name="firstName"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="exampleInputLastName"&gt;Last Name&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="exampleInputLastName" placeholder="Username" name="lastName"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="exampleInputAddress"&gt;Address&lt;/label&gt;
                  &lt;textarea class="form-control" id="exampleInputAddress" placeholder="Address" name="address"&gt;&lt;/textarea&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="exampleInputContact"&gt;Contact&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="exampleInputContact" placeholder="Contact" name="contact"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="exampleInputUsername"&gt;Username&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="exampleInputUsername" placeholder="Username" name="userName"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="exampleInputPassword"&gt;Password&lt;/label&gt;
                  &lt;input type="password" class="form-control" id="exampleInputPassword" placeholder="Password" name="passWord"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="examoleInputType"&gt;Type&lt;/label&gt;
                      &lt;select id="target" class="size form-control" name="selectType"&gt;
                          &lt;option value="default" selected="selected"&gt;--SELECT--&lt;/option&gt;
                          &lt;option value="User"&gt;User&lt;/option&gt;
                          &lt;option value="Admin"&gt;Admin&lt;/option&gt;    
                      &lt;/select&gt;
              &lt;/div&gt;
  
              &lt;div class="well modal-footer" id="bg"&gt;
              &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
              &lt;button type="button" class="btn btn-primary" name="save"&gt;Save changes&lt;/button&gt;
          &lt;/div&gt;
          &lt;/form&gt;
        &lt;/div&gt;
  
      &lt;/div&gt;&lt;!-- /.modal-content --&gt;
    &lt;/div&gt;&lt;!-- /.modal-dialog --&gt;
  &lt;/div&gt;&lt;!-- /.modal --&gt;
  </code></pre>
  
  <p>PS: I've put all the php code inside my modal along with the url of my database connection. The modal is place below the end tag html of this code. I'm using bootstrap from getbootstrap.com by the way.</p>
  
  <pre><code>&lt;?php
  session_start();
  
  if(isset($_SESSION['username'])!="" ) {
      header("location: home.php");
  } 
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;title&gt;Login&lt;/title&gt;
  
  
  &lt;link rel = "stylesheet" href="bootstrap/css/bootstrap.min.css"&gt;
  &lt;script src="js/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  &lt;?php
  require('config/db_conn.php');
  
  ?&gt;
  
  &lt;/head&gt;
  &lt;style type="text/css"&gt;
  body
  {
  background-color: #6BBEE4;
  
  }
  
  .createwrapper
  {
  width: 500px;
  height: 300px;
  margin: 0 auto;
  margin-top: 118px;
  }
  
  a:hover
  {
  text-decoration: none
  }
  
  .size
  {
  width: 150px;
  }
  
  #bg
  {
  background-color: #6BBEE4;  
  
  }
  
  &lt;/style&gt;
  &lt;body&gt;
  
  
  &lt;?php
  if(isset($_POST['submit']))
  {
      if($_POST['type'] == "User")
      {
      $user = $_POST['username'];
      $pass = $_POST['password'];
      $type = $_POST['type'];
  
  
      $query = mysql_query("SELECT * FROM customer where c_user = '$user' &amp;&amp; c_pass = '$pass' &amp;&amp; c_type = '$type'");
  
      $data = mysql_fetch_array($query);
  
      $_SESSION['username'] =  $data['c_user'];
      $_SESSION['password'] =  $data['c_pass'];
      $_SESSION['name'] = $data['c_fname'];
  
      header("location: home.php");
      }
  
      elseif($_POST['type'] == "Admin")
      {
          echo "Were still working!!";
      }
  
      else
      {
      header("location: login.php");
      }
  }
  ?&gt;
  
  &lt;script type="text/javascript"&gt;
  
  $(document).ready(function() {
      $('#signup').click (function() {
          $('#myModal').modal(show);
  
      });
  
  
  })
  
  
  &lt;/script&gt;
  
  &lt;div class = "well createwrapper"&gt;
  &lt;form method="post" action=""&gt;
    &lt;div class="form-group"&gt;
      &lt;label for="exampleInputUsername"&gt;Username&lt;/label&gt;
      &lt;input type="text" class="form-control" id="exampleInputUsername" placeholder="Username" name="username"&gt;
    &lt;/div&gt;
    &lt;div class="form-group"&gt;
      &lt;label for="exampleInputPassword1"&gt;Password&lt;/label&gt;
      &lt;input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password"&gt;
    &lt;/div&gt;
      &lt;div class="form-group"&gt;
      &lt;label for="examoleInputType"&gt;Type&lt;/label&gt;
  
      &lt;select id="target" class="size form-control" name="type"&gt;
      &lt;option value="default" selected="selected"&gt;--SELECT--&lt;/option&gt;
      &lt;option value="User"&gt;User&lt;/option&gt;
      &lt;option value="Admin"&gt;Admin&lt;/option&gt;    
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;button class="btn btn-primary" name="submit"&gt;Submit&lt;/button&gt;
    &lt;div class="pull-right"&gt;
    &lt;font color="428BCA"&gt; Don't have an account? &lt;/font&gt;
    &lt;button class="btn btn-primary " name="signup" data-toggle="modal" data-target="#myModal" id="signup"&gt;Sign Up&lt;/button&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>