title: Getting data from the database to the input type of form but there is an error of undefined variable
body: <p>I'm trying to edit the data that I've inputted to my database using this form.</p>
  
  <pre><code>&lt;form method="POST"&gt;
                          &lt;table align ="center"&gt;
                          &lt;br&gt;
                              &lt;tr&gt;&lt;td&gt;First Name: &lt;/td&gt; &lt;td&gt;&lt;input type="text" name="first" pattern="[A-Za-z]{1,}" 
                              title="A-Z only" required value="&lt;?php echo $query2['fname']; ?&gt;"&gt;&lt;/td&gt; &lt;/tr&gt;
  
                              &lt;tr&gt;&lt;td&gt;Middle Initial: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="middle" 
                              value="&lt;?php echo $query2['middleinitial'] ?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                              &lt;tr&gt;&lt;td&gt;Last Name:&lt;/td&gt;&lt;td&gt; &lt;input type="text" name="last"
                              value="&lt;?php echo $query2['lname'] ?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                              &lt;tr&gt;&lt;td&gt;Contact Number:&lt;/td&gt;&lt;td&gt; &lt;input type="tel" name="contact" maxlength="11" 
                              value="&lt;?php echo $query2['contactnum'] ?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                              &lt;tr&gt; &lt;td&gt;Province: &lt;/td&gt;&lt;td&gt; &lt;input type="text" name="provincee" 
                              value="&lt;?php echo $query2['province'] ?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                              &lt;tr&gt; &lt;td&gt;City: &lt;/td&gt;&lt;td&gt; &lt;input type="text" name="cityy" 
                              value="&lt;?php echo $query2['city'] ?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                              &lt;tr&gt; &lt;td&gt;Username:&lt;/td&gt;&lt;td&gt; &lt;input type="email" name="usernamee" 
                              value="&lt;?php echo $query2['username'] ?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                              &lt;tr&gt;&lt;td&gt;Password:&lt;/td&gt;&lt;td&gt; &lt;input type="password" name="pass" 
                              value="&lt;?php echo $query2['password'] ?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                              &lt;tr&gt;&lt;td&gt;&lt;br&gt; &lt;input type="Submit" name="submitt"&gt;&lt;/td&gt;&lt;/tr&gt;
                          &lt;/table&gt;
                          &lt;/form&gt;
  </code></pre>
  
  <p>Here's my php code.</p>
  
  <pre><code>if(isset($_GET['id'])){
  
                              $userid=$_GET['id'];
  }
  
                              if(isset($_POST['submitt'])){
                              $firstname= mysqli_real_escape_string($mysqli,$_POST['first']);
                              $middleinitial= mysqli_real_escape_string($mysqli,$_POST['middle']);
                              $lastname= mysqli_real_escape_string($mysqli,$_POST['last']);
                              $contactnumber= mysqli_real_escape_string($mysqli,$_POST['contact']);
                              $province= mysqli_real_escape_string($mysqli,$_POST['provincee']);
                              $city = mysqli_real_escape_string($mysqli,$_POST['cityy']);
                              $username= mysqli_real_escape_string($mysqli,$_POST['usernamee']);
                              $password= mysqli_real_escape_string($mysqli,$_POST['pass']); 
  
                           $query=mysqli_query($mysqli, "UPDATE usertbl SET fname='$firstname', 
                           middleinitial='$middleinitial', lname='$lastname',contactnum = '$contactnumber',
                           province = '$province',city= '$city' ,username = '$username' ,
                           password = '$password' where userid='$userid'");
  
  
                            if($query){
  
                                header('location:employees.php');
  
                            }
  
                          $query1=mysqli_query($mysqli,"SELECT * FROM usertbl WHERE userid='$userid'");
                          $query2 = mysqli_fetch_array($query1);
                              }
  </code></pre>
  
  <p>The error that keeps on showing is undefined variable on the input type values of the information on the form. I'm trying to get the data from the database, but I can't seem to get it. What seems to be the problem with this? </p>
  
  <p>These are the errors:
  <br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>372</b><br /></p>
  
  <p><br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>375</b><br /></p>
  
  <p><br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>378</b><br /></p>
  
  <p><br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>381</b><br /></p>
  
  <p><br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>384</b><br /></p>
  
  <p><br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>387</b><br /></p>
  
  <p><br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>390</b><br /></p>
  
  <p><br /><b>Notice</b>:  Undefined variable: query2 in <b>C:\xampp\htdocs\thesis2\admin\pages\editemployee.php</b> on line <b>390</b><br /></p>