title: Update sql table on php using html forms
body: <p>I have been trying to update a record on my table by using an html form. I am able to create and delete a record successfully but I am unable to update it. I am not sure what I have done wrong. Could it be the SQL query syntax? or is my save button not calling my condition statement? I would appreciate any advice given. </p>
  
  <p>ps. I am aware that my SQL database is open to SQL injection. It will be implemented soon!</p>
  
  <pre><code>&lt;?php
      include('partregister2.php');
      $epr='';
      $msg='';
      if(isset($_GET['epr']))
      $epr=$_GET['epr'];
  
      //+++++++++++++++ UPDATE PARTICIPANTS RECORD +++++++++++++++++
      if($epr=='saveup'){
          $Name=$_POST['name'];
          $Surname=$_POST['surname'];
          $Date_of_Birth=$_POST['dob'];
          $Age_at_Camp=$_POST['age'];
          $Branch=$_POST['branch'];
          $Gender=$_POST['gender'];
          $Address=$_POST['address'];
          $Contact_No=$_POST['contactNo'];
          $Next_of_Kin=$_POST['nextKin'];
          $Kin_ContactNo=$_POST['kinContact'];
          $Attendance_Camp=$_POST['attendCamp'];
          $Attendance_School=$_POST['attendSchool'];
          $Comments=$_POST['comments'];
          $event_name_FK=$_POST['Event_Name'];
          $Room_Name_FK=$_POST['Room_Name'];
          $a_sql = mysql_query("UPDATE participants SET Name='$Name',Surname='$Surname',Date_of_Birth ='$Date_of_Birth',Age_at_Camp ='$Age_at_Camp',Branch ='$Branch',Gender ='$Gender',Address ='$Address',
          Contact_No ='$Contact_No',Next_of_Kin ='$Next_of_Kin',Kin_ContactNo = '$Kin_ContactNo',Attendance_Camp ='$Attendance_Camp',Attendance_School ='$Attendance_School',Comments ='$Comments',event_name_FK ='$event_name_FK',Room_Name_FK ='$Room_Name_FK' WHERE partID='$id'");
          if(a_sql)
              header("location:index.php");
          else
              $msg='Error : '.mysql_error();
      }
  ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
  &lt;?php
      if($epr=='update'){
          $id=$_GET['id'];
          $row=mysql_query("SELECT * FROM participants WHERE partID='$id'");
          $st_row=mysql_fetch_array($row);
          ?&gt;
      &lt;h2 align="center"&gt;Update Participant Records&lt;/h2&gt;
          &lt;form method="POST" action='index.php?epr=saveup'&gt;
          &lt;table align="center"&gt;
  
          &lt;tr&gt;
          &lt;td&gt;First Name:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='name' value="&lt;?PHP echo $st_row['Name'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Surname:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='surname' value="&lt;?PHP echo $st_row['Surname'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Date of Birth:&lt;/td&gt;
          &lt;td&gt;&lt;input type='date' name ='dob' value="&lt;?PHP echo $st_row['Date_of_Birth']  ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Age at Camp:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='age' value="&lt;?PHP echo $st_row['Age_at_Camp'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Branch:&lt;/td&gt;
          &lt;td&gt;&lt;select name='branch' value="&lt;?PHP echo $st_row['Branch'] ?&gt;"/&gt;
          &lt;option&gt;&lt;/option&gt;
          &lt;option&gt;Brixton&lt;/option&gt;
          &lt;option&gt;North London&lt;/option&gt;
          &lt;option&gt;East London&lt;/option&gt;
          &lt;option&gt;Southall&lt;/option&gt;
          &lt;option&gt;Leicester&lt;/option&gt;
          &lt;option&gt;Newport&lt;/option&gt;
          &lt;option&gt;Liverpool&lt;/option&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;/select&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Gender:&lt;/td&gt;
          &lt;td&gt;Male&lt;input type="radio" value="male" name="gender" value="&lt;?PHP echo $st_row['Gender'] ?&gt;"/&gt;
          Female&lt;input type="radio" value="female" name="gender" value="&lt;?PHP echo $st_row['Gender'] ?&gt;" /&gt;&lt;td/&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Address:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='address' value="&lt;?PHP echo $st_row['Address'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Contact No:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='contactNo' value="&lt;?PHP echo $st_row['Contact_No'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Next of Kin:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='nextKin' value="&lt;?PHP echo $st_row['Next_of_Kin'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Kin's Contact No:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='kinContact' value="&lt;?PHP echo $st_row['Kin_ContactNo'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Attendance at Camp:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='attendCamp' value="&lt;?PHP echo $st_row['Attendance_Camp'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Attendance at Sunday School:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='attendSchool' value="&lt;?PHP echo $st_row['Attendance_School'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;Comments:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name ='comments' value="&lt;?PHP echo $st_row['Comments'] ?&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  
          &lt;tr&gt;
          &lt;td&gt;Event Name:&lt;/td&gt;
          &lt;td&gt;&lt;select name='Event_Name' value="&lt;?PHP echo $st_row['event_name_FK'] ?&gt;"&gt;
  &lt;?php
          $res = mysql_query("SELECT * FROM events");
          while($row=mysql_fetch_array($res))
          {
  ?&gt;
          &lt;option&gt;
          &lt;?php echo $row["Event_Name"]; ?&gt;
          &lt;/option&gt;
          &lt;?php } ?&gt;
          &lt;/tr&gt;
          &lt;/select&gt;
  
  
          &lt;tr&gt;
          &lt;td&gt;Allocate Room:&lt;/td&gt;
          &lt;td&gt;&lt;select name='Room_Name' value="&lt;?PHP echo $st_row['Room_Name_FK'] ?&gt;"&gt;
  &lt;?php
          $res = mysql_query("SELECT * FROM rooms");
          while($row=mysql_fetch_array($res))
          {
  ?&gt;
          &lt;option&gt;
          &lt;?php echo $row["Room_Name"]; ?&gt;
          &lt;/option&gt;
          &lt;?php } ?&gt;
          &lt;/td&gt;
          &lt;/select&gt;
          &lt;/tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type ='submit' name='save'/&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/form&gt;
      &lt;?php } else{
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>