title: Display welcome message with the username in php & mysql
body: <p>I am creating a form for log in and log out .
  My problem is when a user submit their username and password then display welcome message with that username.Files are given below.</p>
  
  <p>include.php</p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  
  $host = "VKSolutions";
  
  $username = "VKSolutions";
  
  $password = "VKSolutions@1";
  
  $db = "VKSolutions";
  
  @mysql_connect($host,$username,$password) or die ("error");
  
  @mysql_select_db($db) or die("error");
  
  ?&gt;
  </code></pre>
  
  <p>login.php</p>
  
  <pre><code>&lt;?php
  
  require_once('include.php');
  
  $error = '';
  
  $form = $_POST['submit'];
  
  $user = $_POST['user'];
  
  $password = $_POST['password'];
  
  if( isset($form) ) {
  
  if( isset($user) &amp;&amp; isset($password) &amp;&amp; $user !== '' &amp;&amp; $password !== '' ) {
  
  
  $sql = mysql_query("SELECT * FROM `accounts` WHERE user='$user' and
  password='$password';");
  
  if( mysql_num_rows($sql) != 0 ) { //success
  
  $_SESSION['logged-in'] = true;
  
  header('Location: members.php');
  
  exit;
  
  } else { $error = "Incorrect login info"; }
  
  } else { $error = 'All information is not filled out correctly';}
  
  }
  
  ?&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  
  &lt;title&gt;Login&lt;/title&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
   &lt;table width="80%" border="0"&gt;&lt;form action="&lt;?php $PHP_SELF; ?&gt;" method="post" &gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;label&gt;Employee Name:&lt;/label&gt;&lt;/td&gt;
       &lt;td&gt;&lt;input name="user" placeholder="Enter Name" type="text" value="&lt;?php echo     "$user";?&gt;" /&gt;&lt;/td&gt;
     &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;label&gt;Password:&lt;/label&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input name="password" placeholder="Enter Password" type="password" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&lt;input valin="right" name="submit" type="submit" value="Log In" /&gt;&lt;/td&gt;
    &lt;/tr&gt;&lt;/form&gt;
  &lt;/table&gt;
  &lt;?php
  
  echo "&lt;br /&gt;&lt;span style=\"color:red\"&gt;$error&lt;/span&gt;";
  
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>members.php</p>
  
  <pre><code>&lt;?php
  
   require_once('include.php');
  
  if ( !isset($_SESSION['logged-in']) || $_SESSION['logged-in'] !== true) {
  
  header('Location: login.php');
  
  exit;
  
  }
  
  ?&gt;
  
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  &lt;title&gt;Staff Area&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div style="margin-top:50px; color:#00F; margin-left:50px; font-size:18px;             position:absolute"&gt;Welcome&lt;?php echo "$user";?&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>logout.php</p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  // if the user is logged in, unset the session
  
  if (isset($_SESSION['logged-in'])) {
  
  unset($_SESSION['logged-in']);
  
  }
  
  // now that the user is logged out,
  
  // go to login page
  
  header('Location: login.php');
  
  ?&gt;
  </code></pre>
  
  <p>In my members.php it is log in but not display with username. I need that username.
  Please find out what is wrong.
  Thanks.</p>