title: How to UPDATE the data in the database using php
body: <p>im currently creating an <code>edit.php</code> page which enables the user to edit the specified data which the user wanted. I followed the tutorial but it doesn't give the results that i wanted to. When I run the <code>edit.php</code>, it just display as i wanted but after i clicked <code>submit</code> button, there were nothing changed to the data in the database.</p>
  
  <p>This is the code:</p>
  
  <pre><code>    &lt;?php
      require('db.php');
      include("auth.php");
      $student_ID=$_REQUEST['student_ID'];
      $query = "SELECT * from student_info where student_ID='$student_ID'"; 
      $result = mysqli_query($con, $query) or die ( mysqli_error());
      $row = mysqli_fetch_assoc($result);
      ?&gt;
      &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Update Student&lt;/title&gt;
      &lt;link rel="stylesheet" href="css/style.css" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div class="form"&gt;
      &lt;p&gt;&lt;a href="dashboard.php"&gt;Dashboard&lt;/a&gt; 
       | &lt;a href="insert.php"&gt;Insert New Record&lt;/a&gt; 
       | &lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/p&gt;
      &lt;h1&gt;Update Student&lt;/h1&gt;
      &lt;?php
      $status = "";
      if(isset($_POST['submit']) &amp;&amp; $_POST['submit']==1)
      {
      $student_ID=$_POST['student_ID'];
      $school_ID =$_POST['school_ID'];
      $student_name =$_POST['student_name'];
      $student_class =$_POST['student_class'];
      mysqli_query($con, $update) or die(mysqli_error());
      $status = "Student Record Updated Successfully. &lt;/br&gt;&lt;/br&gt;
      &lt;a href='view.php'&gt;View Updated Record&lt;/a&gt;";
      echo '&lt;p style="color:#FF0000;"&gt;'.$status.'&lt;/p&gt;';
      }else {
      ?&gt;
      &lt;div&gt;
      &lt;form name="form" method="post" action=""&gt; 
      &lt;p&gt;&lt;input type="text" name="student_ID" placeholder="Enter Student ID"
      required value=&lt;?php echo $row['student_ID'];?&gt; /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;input type="text" name="school_ID" placeholder="Enter School ID" 
      required value="&lt;?php echo $row['school_ID'];?&gt;" /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;input type="text" name="student_name" placeholder="Enter Student Name" 
      required value="&lt;?php echo $row['student_name'];?&gt;" /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;input type="text" name="student_class" placeholder="Enter Student     Class"
      required value="&lt;?php echo $row['student_class'];?&gt;" /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;input name="submit" type="submit" value="Submit" /&gt;&lt;/p&gt;
      &lt;/form&gt;
      &lt;?php } ?&gt;
      &lt;/div&gt;
      &lt;/div&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>If you have any suggestion or any improvement or any link can help me solving this problem, please do so.</p>
  
  <p>This is the original code that the author gave:</p>
  
  <pre><code>    &lt;?php
      require('db.php');
      include("auth.php");
      $id=$_REQUEST['id'];
      $query = "SELECT * from new_record where id='".$id."'"; 
      $result = mysqli_query($con, $query) or die ( mysqli_error());
      $row = mysqli_fetch_assoc($result);
      ?&gt;
      &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Update Record&lt;/title&gt;
      &lt;link rel="stylesheet" href="css/style.css" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div class="form"&gt;
      &lt;p&gt;&lt;a href="dashboard.php"&gt;Dashboard&lt;/a&gt; 
      | &lt;a href="insert.php"&gt;Insert New Record&lt;/a&gt; 
      | &lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/p&gt;
      &lt;h1&gt;Update Record&lt;/h1&gt;
      &lt;?php
      $status = "";
      if(isset($_POST['new']) &amp;&amp; $_POST['new']==1)
      {
      $id=$_REQUEST['id'];
      $trn_date = date("Y-m-d H:i:s");
      $name =$_REQUEST['name'];
      $age =$_REQUEST['age'];
      $submittedby = $_SESSION["username"];
      $update="update new_record set trn_date='".$trn_date."',
      name='".$name."', age='".$age."',
      submittedby='".$submittedby."' where id='".$id."'";
      mysqli_query($con, $update) or die(mysqli_error());
      $status = "Record Updated Successfully. &lt;/br&gt;&lt;/br&gt;
      &lt;a href='view.php'&gt;View Updated Record&lt;/a&gt;";
      echo '&lt;p style="color:#FF0000;"&gt;'.$status.'&lt;/p&gt;';
      }else {
      ?&gt;
      &lt;div&gt;
      &lt;form name="form" method="post" action=""&gt; 
      &lt;input type="hidden" name="new" value="1" /&gt;
      &lt;input name="id" type="hidden" value="&lt;?php echo $row['id'];?&gt;" /&gt;
      &lt;p&gt;&lt;input type="text" name="name" placeholder="Enter Name" 
      required value="&lt;?php echo $row['name'];?&gt;" /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;input type="text" name="age" placeholder="Enter Age" 
      required value="&lt;?php echo $row['age'];?&gt;" /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;input name="submit" type="submit" value="Update" /&gt;&lt;/p&gt;
      &lt;/form&gt;
      &lt;?php } ?&gt;
      &lt;/div&gt;
      &lt;/div&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>Btw, i dont know what this code meant for. I just follow the tutorial.</p>
  
  <pre><code>    if(isset($_POST['submit']) &amp;&amp; $_POST['submit']==1)
  </code></pre>
  
  <p>I'm a newbie in this coding world. Thanks</p>