title: Only a few fields are getting added while using an HTML form with PHP to add data to MySQL
body: <p>I did a form using HTML and tried to insert the data using PHP to MySQL database. But only a few cells in the database are getting added. Couldn't figure out what is wrong. Please help. Thanks in advance.</p>
  
  <p>Here is my code, of the page which has the form (patienthistory.php)</p>
  
  <pre><code>&lt;?php 
  
    // Connects to your Database 
  
  mysql_connect("localhost", "root", "") or die(mysql_error()); 
  
  mysql_select_db("cleftdb") or die(mysql_error()); 
  
  
  //checks cookies to make sure they are logged in 
  
  if(isset($_COOKIE['ID_my_site'])) 
  
  { 
  
  $username = $_COOKIE['ID_my_site']; 
  
  $pass = $_COOKIE['Key_my_site']; 
  
      $check = mysql_query("SELECT * FROM members WHERE username = '$username'")or die(mysql_error()); 
  }
  else 
  
  //if the cookie does not exist, they are taken to the login screen 
  
  {            
  
  header("Location: login.php"); 
  
   } 
  
  $check = mysql_query("SELECT id FROM members WHERE username = '$username'")or die(mysql_error());
  while ($row = mysql_fetch_assoc($check)) {
  $id = $row["id"];
  }
  
  
  
  echo '&lt;form action="savepatienthistory.php" method=post /&gt;';
  
  echo '&lt;input type="hidden" name="id" value="'.$id.'"&gt;';
  
  echo '&lt;p&gt;Patient ID: &lt;input type="text" name="pid" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;First Name: &lt;input type="text" name="fname" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Last Name: &lt;input type="text" name="lname" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Date of birth : &lt;input type="date" name="dob" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Sex: 
  &lt;select name="sex"&gt;
  &lt;option value="Male"&gt;Male&lt;/option&gt;
  &lt;option value="Female"&gt;Female&lt;/option&gt;
  &lt;/select&gt;
  &lt;/p&gt;';
  echo '&lt;p&gt;Race: &lt;input type="text" name="race" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Address: &lt;input type="text" name="address" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;GN Division: &lt;input type="text" name="GNdivision" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian First Name: &lt;input type="text" name="Xfname" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian Last Name: &lt;input type="text" name="Xlname" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian Age: &lt;input type="text" name="Xage" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian Occupation: &lt;input type="text" name="Xoccupation" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian NIC number: &lt;input type="text" name="XNICno" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian Race: &lt;input type="text" name="Xrace" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian Address: &lt;input type="text" name="Xaddress" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian GN Division: &lt;input type="text" name="XGNdivision" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian Relationship to the Patient: &lt;input type="text" name="Xrelationship" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Parent/Guardian Country: &lt;input type="text" name="Xcountry" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;General Medical History: 
  &lt;select name="otherproblem"&gt;
      &lt;option value="Nothing"&gt;Nothing&lt;/option&gt;
      &lt;option value="Allergy: Penicillin"&gt;Allergy: Penicillin&lt;/option&gt;
      &lt;option value="Aspirin"&gt;Aspirin&lt;/option&gt;
      &lt;option value="Erythromycin"&gt;Erythromycin&lt;/option&gt;
      &lt;option value="Latex or Rubber Products"&gt;Latex or Rubber Products&lt;/option&gt;
      &lt;option value="Codeine"&gt;Codeine&lt;/option&gt;
      &lt;option value="Tetracycline"&gt;Tetracycline&lt;/option&gt;
      &lt;option value="Germicides/Pesticides, Foods"&gt;Germicides/Pesticides, Foods&lt;/option&gt;
      &lt;option value="Other"&gt;Other&lt;/option&gt;
      &lt;option value="Asthma"&gt;Asthma&lt;/option&gt;
      &lt;option value="Bleeding Disorders"&gt;Bleeding Disorders&lt;/option&gt;
      &lt;option value="Diabetes"&gt;Diabetes&lt;/option&gt;
      &lt;option value="Epilepsy"&gt;Epilepsy&lt;/option&gt;
      &lt;option value="GI disorders"&gt;GI disorders&lt;/option&gt;
      &lt;option value="Heart disease"&gt;Heart disease&lt;/option&gt;
      &lt;option value="Hepatitis"&gt;Hepatitis&lt;/option&gt;
      &lt;option value="Jaundice"&gt;Jaundice&lt;/option&gt;
      &lt;option value="Liver disease"&gt;Liver disease&lt;/option&gt;
      &lt;option value="Neoplasm"&gt;Neoplasm&lt;/option&gt;
      &lt;option value="Psychiatric Problems"&gt;Psychiatric Problems&lt;/option&gt;
      &lt;option value="Respiratory diseases"&gt;Respiratory diseases&lt;/option&gt;
      &lt;option value="Rheumatic fever"&gt;Rheumatic fever&lt;/option&gt;
  &lt;/select&gt;
  &lt;/p&gt;';
  echo '&lt;p&gt;Do patient currently under medical treatment? If yes, what are the medicines: &lt;input type="text" name="medicaltreatment" /&gt;&lt;/p&gt;';
  echo '&lt;p&gt;Do Patient Need Antibiotic Prophylaxis?  
  &lt;select name="antibiotic"&gt;
      &lt;option value="Yes"&gt;Yes&lt;/option&gt;
      &lt;option value="No"&gt;No&lt;/option&gt;
  &lt;/select&gt;
  &lt;/p&gt;';
  
  
  
  echo '&lt;input type="submit" value="Submit"&gt;';
  echo '&lt;/form&gt;';
  
  
  ?&gt;
  </code></pre>
  
  <p>and my savepatienthistory.php code,</p>
  
  <pre><code>&lt;?php 
   // Connects to your Database 
  
   mysql_connect("localhost", "root", "") or die(mysql_error()); 
  
   mysql_select_db("cleftdb") or die(mysql_error()); 
  
  
   $id = $_POST['id'];
   $pid = $_POST['pid'];
   $fname = $_POST['fname'];
   $lname = $_POST['lname'];
   $dob = $_POST['dob'];
   $sex = $_POST['sex'];
   $race = $_POST['race'];
   $address = $_POST['address'];
   $GNdivision = $_POST['GNdivision'];
   $Xfname = $_POST['Xfname'];
   $Xlname = $_POST['Xlname'];
   $Xage = $_POST['Xage'];
   $Xoccupation = $_POST['Xoccupation'];
   $XNICno = $_POST['XNICno'];
   $Xrace = $_POST['Xrace'];
   $Xaddress = $_POST['Xaddress'];
   $XGNdivision = $_POST['XGNdivision'];
   $Xrelationship = $_POST['Xrelationship'];
   $Xcountry = $_POST['Xcountry'];
   $otherproblem = $_POST['otherproblem'];
   $medicaltreatment = $_POST['medicaltreatment'];
   $antibiotic = $_POST['antibiotic'];
  
  
   $sql = "INSERT into history (id) VALUES ('$id')";
  
   $sql = "INSERT into history (pid) VALUES ('$pid')";
   $sql = "INSERT into history (fname) VALUES ('$fname')";
   $sql = "INSERT into history (lname) VALUES ('$lname')";
   $sql = "INSERT into history (dob) VALUES ('$dob')";
   $sql = "INSERT into history (sex) VALUES ('$sex')";
   $sql = "INSERT into history (race) VALUES ('$race')";
   $sql = "INSERT into history (address) VALUES ('$address')";
   $sql = "INSERT into history (GNdivision) VALUES ('$GNdivision')";
   $sql = "INSERT into history (Xfname) VALUES ('$Xfname')";
   $sql = "INSERT into history (Xlname) VALUES ('$Xlname')";
   $sql = "INSERT into history (Xage) VALUES ('$Xage')";
   $sql = "INSERT into history (Xoccupation) VALUES ('$Xoccupation')";
   $sql = "INSERT into history (XNICno) VALUES ('$XNICno')";
   $sql = "INSERT into history (Xrace) VALUES ('$Xrace')";
   $sql = "INSERT into history (Xaddress) VALUES ('$Xaddress')";
   $sql = "INSERT into history (XGNdivision) VALUES ('$XGNdivision')";
   $sql = "INSERT into history (Xrelationship) VALUES ('$Xrelationship')";
   $sql = "INSERT into history (Xcountry) VALUES ('$Xcountry')";
   $sql = "INSERT into history (otherproblem) VALUES ('$otherproblem')";
   $sql = "INSERT into history (medicaltreatment) VALUES ('$medicaltreatment')";
   $sql = "INSERT into history (antibiotic) VALUES ('$antibiotic')";
  
  
  
   if(!mysql_query($sql)){
  die('Error: '.mysql_error());
   } 
  
   mysql_close();
  
   ?&gt;
  </code></pre>
  
  <p>and here is a screenshot of the added values to db 
  <img src="https://i.imgur.com/Av04D.png" alt="screenshot"> </p>