title: PHP/Mysql authentication script getting NULL result from query
body: <p>I am working on a test project, trying to learn more about PHP and Mysql and what not.  So I have decided to build an Authentication engine for my test website but I am having issues with the query.</p>
  
  <p>Basically, if I run...</p>
  
  <pre><code>SELECT * FROM users WHERE name="tester" and passwd=md5('pass');
  </code></pre>
  
  <p>from the mysql console, I get...</p>
  
  <pre><code>+--------+---------------+----------------------------------+
  | name   | email         | passwd                           |
  +--------+---------------+----------------------------------+
  | tester | test@test.com | 1a1dc91c907325c69271ddf0c944bc72 |
  +--------+---------------+----------------------------------+
  1 row in set (0.00 sec)
  </code></pre>
  
  <p>However,when I issue the same query (at least I think it is the same) from my PHP code (see below) I appear to be getting a NULL result, thus authentication fails.</p>
  
  <pre><code>&lt;?php
      include 'db_connect.php';
  
      $username = $_POST['username'];
      $passwd = $_POST['passwd'];
  
      // To protect MySQL injection (more detail about MySQL injection)
      //$username = stripslashes($username);
      //$passwd = stripslashes($passwd);
      //$username = mysql_real_escape_string($username);
      //$passwd = mysql_real_escape_string($passwd);
  
      //Encrypted password
      $secpasswd = md5($passwd);
  
      $sql="SELECT * FROM users WHERE name='$username' and passwd = $secpasswd";
  
      $result=mysql_query($dbconnect,$sql);
      var_dump($result);
  
      // Mysql_num_row is counting table row
      $count=mysql_num_rows($result);
      //var_dump($count);
  
      // If result matched $myusername and $mypassword, table row must be 1 row
      if($count==1){
  
          // Register $myusername, $mypassword and redirect to file "login_success.php"
          session_register("username");
          session_register("passwd"); 
          header("location:login_success.php");
          }
      else {
          echo "Wrong Username or Password";
          }
      ob_end_flush();
  ?&gt;
  </code></pre>