-2

This is my codes i dont think there is something wrong with my query but i keep getting this error "mysql_num_rows() expects parameter 1 to be resource, boolean given in" i checked my database to make sure nothing is spelled wrong and the quotation marks but still this error

                                    if(isset($_POST['e_username']) && isset($_POST['e_password'])){

                                        $e_username = preg_replace('#[^A-Za-z0-9]#i','', $_POST['e_username']);
                                        $e_password = preg_replace('#[^A-Za-z0-9]#i','',$_POST['e_password']);

                                        $e_password_md5 = md5($e_password);


                                        $sql = @mysql_query("SELECT * FROM employee_db WHERE username='$e_username' AND password ='$e_password_md5' LIMIT 1") || die("Unable to run query".mysql_error());
                                        $userCount = mysql_num_rows($sql);

                                            if ($userCount == 1){

                                                $_SESSION['e_username'] = $e_username;
                                                header("Location:profile.php");
                                                exit();


                                            }else{

                                                //echo "<div class =\"error\">Incorrect Infomation Register --------></div>";
                                            }   

                                        }
T_T
  • 13
  • 1
  • 5
  • 1
    Stop suppressing errors with `@`. How do you ever expect to debug things if you hide any messages that PHP might give you? – Mark Baker Aug 23 '14 at 23:59
  • i already remove that symbol – T_T Aug 24 '14 at 00:00
  • 1
    Why are you refusing to allow your users to have complex passwords? Why are you still using unsalted md5 (it's 2014 for heavens sake, not 1994)? Why are you still using MySQL and not MySQLi or PDO? – Mark Baker Aug 24 '14 at 00:01
  • I am just a beginner and this is my first time using php – T_T Aug 24 '14 at 00:05

1 Answers1

0

The problem is because you have || die(...) at the end of your query - this turns your result into a conditional, i.e. a boolean result.

Try removing the || die(...) and using a different form of error checking, such as a try/catch block, or using mysql_errno() (the result of this method is zero if there is no error; or a positive integer if there is).

Mark Ormesher
  • 1,967
  • 2
  • 24
  • 33