title: PHP - login script
body: <p>I have this login script, but for some reason its not working. I checked the database, the form, and I have re-written the script in like 5 different ways; however, they all have the same problem, it does not start the session. Here is the code:</p>
  
  <pre><code>&lt;?php 
  session_start();
  
  //connect and select DB
  mysql_connect ("localhost", "root", "") or die ('Error: ' . mysql_error());
  mysql_select_db('usr_info')or die ("cannot select DB :(");
  
  //transfer values sent from form
  $usrname = $_POST['usrname'];
  $passwrd = $_POST['passwrd'];
  
  //injection protection
  $usrname = stripslashes($usrname);
  $passwrd = stripslashes($passwrd);
  $usrname = mysql_real_escape_string($usrname);
  $passwrd = mysql_real_escape_string($passwrd);
  
  $sql = "SELECT * FROM usrs
          WHERE usremail='$usrname'
          and passwrd='".md5($_POST['passwrd'])."'";
  $result = mysql_query($sql);
  
  //count the number of rows found with the given info
  $count = mysql_num_rows($result);
  
  //the matched result must be equal to 1
  if ($count == 1) {
      $_SESSION['u_name'] = $usrname;
      header("Location: ../../landing.php");
      exit();
  }
  else {
      echo "Wrong Username or Password";
  }
  </code></pre>
  
  <p>this is the form im using:</p>
  
  <pre><code>&lt;div id="login-signup" class="letters2"&gt;&lt;a href="javascript:blankfunction()"&gt;Login | Signup&lt;/a&gt;&lt;/div&gt;
  &lt;div id="point-1" class="point-1"&gt;&lt;img src="site-wide/point-1.png" width="405" height="131" /&gt;
    &lt;div id="login-form"&gt;
    &lt;form id="login" method="POST" action="site-wide/effects/login.php"&gt;
      &lt;label for="username"&gt;&lt;/label&gt;
      &lt;input type="text" name="usrname" id="usrname" value="email" onfocus="clearMe(this);" onblur="unClearMe(this);"/&gt;
      &lt;label for="passwrd"&gt;&lt;/label&gt;
      &lt;input type="password" name="passwrd" id="passwrd" value="password" onfocus="clearMe(this);" onblur="unClearMe(this);"/&gt;
      &lt;input type="image" src="site-wide/submit.png" name="submit" id="submit" value="login"/&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>this is the usrs table in my db:</p>
  
  <p>usrs</p>
  
  <pre><code>Field    Type          Null  Default  Comments  
  ID           int(4)        No  
  usrfname     varchar(15)   No    
  usrlname     varchar(15)   No        
  usremail     varchar(45)   No   
  passwrd      varchar(8)    No  
  usrage       int(3)        No 
  usrgender    varchar(7)    No  
  </code></pre>
  
  <p>I found the answer xD .. the problem was the database. the password field only had 8 characters whereas the actuall md5 password had over 15. so all i did was increase the number of characters the field can handle and viola!</p>