title: Creating Php Multi User Login
body: <p>I have a database with 2 tables, table1 stores only id, username and password, while table2 stores id, username, date, and other information.
  My question now is how can i set my codes in such a way that each time user A logs in, and click on "view profile" he or she can only see there own profile based on there username and not other peoples profile. the same goes to user B, user C and user D and so on.</p>
  
  <p>My code for the log is:
      
  
  <pre><code>session_start();
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  if ($username&amp;&amp;$password)
  
  {
  $connect = mysql_connect("localhost","root","") or die("cannot connect!");
  mysql_select_db("uloaku") or die("cannot find data base!");
  $query = mysql_query ("SELECT * FROM keyaku WHERE    username='".mysql_real_escape_string($username)."' AND   password='".mysql_real_escape_string($password)."'");
  $numrows = mysql_num_rows($query);
  
  if ($numrows!=0)
  {
      while ($row = mysql_fetch_assoc($query))
      {
      $dbusername = $row['username'];
      $dbpassword = $row['password'];
  }
      if ($username==$dbusername&amp;&amp;$password=$dbpassword)
  {
      echo "Welcome $username";
  }
  else
      echo "Invalid Password";
  }
  else
  die("Invalid User");
  
  }
  
  else
   die("Please Enter a UserName and Password.");
  
  ?&gt; 
  </code></pre>
  
  <p>My code to view profile is:</p>
  
  <pre><code>&lt;?php
  session_start();
  $con = mysql_connect("localhost","root","");
  mysql_select_db("uloaku", $con);
  $count = 1;
  
  $y = mysql_query("SELECT * FROM transaction WHERE id=24");
  if(mysql_num_rows($y) != 0){
  
  echo "&lt;table border=\"1\" width=\"800\" &gt;";
  echo "&lt;tr id=\"bold\"&gt;
  &lt;td&gt;No&lt;/td&gt;
  &lt;td align=\"center\" width=\"120\"&gt;Account Owner&lt;/td&gt;
  &lt;td align=\"center\" width=\"120\"&gt;Deposit Date&lt;/td&gt;
  &lt;td align=\"center\" id=\"bold\" width=\"120\"&gt;Current Balance&lt;/td&gt;
  &lt;td align=\"center\" id=\"bold\" width=\"90\"&gt;Intrest&lt;/td&gt;
  &lt;td align=\"center\" width=\"150\"&gt;Available Balance&lt;/td&gt;
  &lt;td align=\"center\"&gt;Account Status&lt;/td&gt;
  &lt;/tr&gt;";
  
  while ($z = mysql_fetch_array($y, MYSQL_BOTH)){
          echo "&lt;tr&gt;
          &lt;td&gt;".$count++."&lt;/td&gt;
          &lt;td id=\"color\" align=\"center\"&gt;".$z[1]."&lt;/td&gt;
          &lt;td id=\"color\" align=\"center\"&gt;".$z[2]."&lt;/td&gt;
          &lt;td id=\"color\" align=\"center\"&gt;".$z[3]."&lt;/td&gt;
          &lt;td id=\"color\" align=\"center\"&gt;".$z[4]."&lt;/td&gt;
          &lt;td id=\"color\" align=\"center\"&gt;".$z[5]."&lt;/td&gt;
          &lt;td id=\"color3\" align=\"left\"&gt;".$z[6]."&lt;/td&gt;
          &lt;/tr&gt;";
      }
      echo "&lt;/table&gt;";
      }
  ?&gt;
  </code></pre>
  
  <p>Hope someone can help me out, will really appreciat it if a full code is given for example or correction so other people that have similar problem can refer and make corrections. Thanks</p>