title: PHP MYSQL - UPDATE user profile with SESSION
body: <p>I'm trying to update user profile with session. Suppose, the user profile page will update accordingly to the profile of the logged in user. Here's the sample code of user_profile.php:-</p>
  
  <pre><code>&lt;?php
   session_start(); 
   ob_start();
  
   include("../function/dbconnect.php");
   include("header.php");
  ?&gt;
  
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;?php
  if(isset($_SESSION['VALID_USER'])){
  
  if(isset($_POST['submit']))
  {
      $username = $_POST['username'];
      $password = $_POST['password'];
  
      $s=mysql_query("UPDATE tbl_staffs SET username='$username', password='$password' WHERE username='".mysql_real_escape_string($_SESSION["VALID_USER"])."'");
  
      if ($s)
          { echo "&lt;script type='text/javascript'&gt;alert('Successful - Record Updated!'); window.location.href = 'user_profile.php';&lt;/script&gt;"; }
      else
          { echo "&lt;script type='text/javascript'&gt;alert('Unsuccessful - ERROR!'); window.location.href = 'user_profile.php';&lt;/script&gt;"; }
  }
  
  $query1=mysql_query("SELECT * FROM tbl_staffs WHERE username='".mysql_real_escape_string($_SESSION["VALID_USER"])."'  AND user_levels = '".mysql_real_escape_string('1')."'");
  $query2=mysql_fetch_array($query1); 
  
  ?&gt;
  
  &lt;form  action="user_profile.php" method="POST"&gt;
  &lt;div&gt;Your  Profile&lt;/div&gt;
  &lt;table  border="0"  align="center"  cellpadding="2"  cellspacing="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;div&gt;Username:&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="username" value="&lt;?php  echo $query2['username'];  ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;div  align="left"  id="tb-name"&gt;Password:&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="password" value="&lt;?php  echo $query2['password'];  ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" name="submit" value="Update" /&gt;
  &lt;/form&gt;
  
  &lt;?php
  //  close  while  loop
  }}
  ?&gt;
  
  &lt;?php
  //  close  connection;
  mysql_close();
  ?&gt;
  &lt;/br&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The page returns blank. There are several other codes that I'm working on for the user_profile.php page too but, the results that I get are the same... I used below codes for admin to update user profile.</p>
  
  <pre><code>include('function/dbconnect.php');
          if(isset($_GET['id']))
          {
              $id=$_GET['id'];
                  if(isset($_POST['submit']))
                  {
                      $username   = $_POST['username'];
                      $email      = $_POST['email'];
                      $password   = $_POST['password'];
                      $user_type  = $_POST['user_type'];
                      $query3     = mysql_query("UPDATE tbl_staffs
                                                SET username='$username', email='$email', password='$password', WHERE id='$id'");
  
                      if ($query3)
                          { echo "&lt;script type='text/javascript'&gt;alert('Successful - Record Updated!'); window.location.href = 'user_list.php';&lt;/script&gt;"; }
                      else
                          { echo "&lt;script type='text/javascript'&gt;alert('Unsuccessful - ERROR!'); window.location.href = 'user_list.php';&lt;/script&gt;"; }
                  }
  
      $query1=mysql_query("SELECT * FROM tbl_staffs WHERE id='$id'");
      $query2=mysql_fetch_array($query1); 
  
  
  
   &lt;form method="post"&gt;
   &lt;tr&gt;
      &lt;td&gt;&lt;b&gt;Username:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="username" style="width:255px" value="&lt;?php echo $query2['username']; ?&gt;" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;b&gt;Email:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="email" style="width:255px" value="&lt;?php echo $query2['email']; ?&gt;" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;b&gt;Password:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="password" style="width:255px" value="&lt;?php echo $query2['password']; ?&gt;" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan="2" align="right"&gt;
      &lt;br /&gt;
          &lt;span title="Click to update the user details"&gt;&lt;input type="submit" name="submit" value="Update" /&gt;&lt;/span&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
  
    &lt;/form&gt;
    &lt;?php
      }
    ?&gt;
  </code></pre>
  
  <p>Apparently, it works fine as it is. Though, when I tried to imply the codes for user so that they can update their own profile, the codes won't work. Where am I doing it wrong? </p>