title: Inserting data into database using AJAX-php using onclick
body: <p>I am trying ajax method to insert data into the database using php. But only the alert message is working and data is not getting inserted into database </p>
  
  <p>My form:</p>
  
  <pre><code>&lt;div class="contactForm"&gt;   
              &lt;h3&gt;Share your contact Details&lt;/h3&gt;
              &lt;form id=register&gt;
                &lt;div class="form-group"&gt;
                  &lt;input type="text" id="team" class="form-control" placeholder="Enter Team Name"&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;input type="text" id="m1" class="form-control" placeholder="Member#1"&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;input type="text" id="m2" class="form-control" placeholder="Member#2"&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;input type="text" id="m3" class="form-control" placeholder="Member#3"&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;input type="text" id="m4" class="form-control" placeholder="Member#4"&gt;
                &lt;/div&gt;
  
                &lt;div class="form-group"&gt;
                  &lt;input type="text" id="email" class="form-control" placeholder="Enter your Email ID"&gt;
                &lt;/div&gt;
  
                &lt;div class="form-group"&gt;
                   &lt;input type="text" id="number" class="form-control" placeholder="Enter your Mobile No."&gt;
                &lt;/div&gt;
                &lt;div class="form-groud"&gt;
  
                    &lt;a type="submit" onclick=register() class="btn"&gt;Register&lt;/a&gt;&lt;/div&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>call function:</p>
  
  <pre><code>function register() {
  var team = document.getElementById("team").value;
  var m1 = document.getElementById("m1").value;
  var m2 = document.getElementById("m2").value;   
  var m3 = document.getElementById("m3").value;
  var m4 = document.getElementById("m4").value;
  var email = document.getElementById("email").value;
  var number = document.getElementById("number").value;
  // Returns successful data submission message when the entered information is stored in database.
  var dataString = 'team=' + team + '&amp;m1=' + m1 + '&amp;m2=' + m2 + '&amp;m3' + m3 + '&amp;m4' + m4 + '&amp;email' + email + '&amp;number' + number;
  if (team == '' || m1 == '' || m2 == '' || m3 == '' || m4 == '' || email == '' || number == '') {
      alert("Please Fill All Fields");
  } else {
      // AJAX code to submit form.
      $.ajax({
          type: "POST",
          url: "workreg.php",
          data: dataString,
          cache: false,
          success: function(html) {
              alert(html);
          }
      });
  }
  return false;
  </code></pre>
  
  <p>}</p>
  
  <p>and here is the php:</p>
  
  <pre><code>&lt;?php
  // Fetching Values From URL
  $team=$_POST['team'];
  $m1=$_POST['m1'];
  $m2=$_POST['m2'];
  $m3=$_POST['m3'];
  $m4=$_POST['m4'];
  $email=$_POST['m4'];
  $number=$_POST['m4'];
  $connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server..
  $db = mysql_select_db("event", $connection); // Selecting Database
  if (isset($_POST['team'])) {
      $query = mysql_query("insert into workshop values ('$team', '$m1', '$m2','$m3','$m4','$email','$number')"); //Insert Query
      echo "Form Submitted succesfully";
  }
  mysql_close($connection); // Connection Closed
  </code></pre>
  
  <p>?></p>
  
  <p>whenever i am clicking register its is just showing alert message but i checked the database no value is getting inserted</p>