-2
     <?php
        session_start();
        include('config.inc'); //for selecting database and connecting to phpmyadmin
        $redirect_page = "Login_page.php";
        if(isset($_POST['email']) && isset($_POST['password'])){
           $email = $_POST['email'];
           $password =$_POST['password'];
           //$_SESSION['email'] = $email;
           //$_SESSION['password'] = $password; 
          if((!empty($email)) && (!empty($password))){
                $query = "SELECT * FROM 'login_details' WHERE (email ='".mysql_real_escape_string($email)."') AND (password ='".mysql_real_escape_string($password)."')";
                $sql_query_run = mysql_query($query);
                if(mysql_num_rows($sql_query_run) == 1){
                  echo "<div>login Success</div>";
                }
                else{
                  echo "<div>Invalid</div>";
                }
          }
          else{  
            header ('Location:'.$redirect_page);
          }
        }
     ?>

I am working on Localhost using Xampp. The above code does not check the required inner most "if" condition, i get a Warning and it outputs "Invalid" that is the inner most "else" part even if i have entered correct email and password that are present in my database. The Warning says:Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\check_user.php on Line 40 The above code is in check_user.php page and i have a different login page (Login_page.php) that has a html form with method ="post" and action ="user_check.php". Please Help...

shubhraj
  • 403
  • 3
  • 12
  • $sql_query_run = mysql_query($query,$connection); – Prashant G Nov 30 '13 at 09:09
  • The `mysql_*` functions are **no longer maintained** and shouldn't be used in any new codebase. It is being phased out in favor of newer APIs. Instead you should use [**prepared statements**](https://www.youtube.com/watch?v=nLinqtCfhKY) with either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). – tereško Nov 30 '13 at 09:11
  • echo your $query and run in phpmyadmin.also FROM 'login_details' should be FROM `login_details` i.e. dont put single quotes – R R Nov 30 '13 at 09:11
  • did you try changing **$sql_query_run = mysql_query($query);** to **$sql_query_run = mysql_query($query,$con);** where $con is your link_identifier – Let me see Nov 30 '13 at 09:20
  • I used this and now its working ---->$sql_query_run = mysql_query($query) or die (mysql_error()); – shubhraj Dec 04 '13 at 06:05

2 Answers2

-1

the error you are getting because your query is not executing.

there wont be single quotes in table name i.e. FROM 'login_details' is wrong.

try

$email=mysql_real_escape_string($email);
$password=mysql_real_escape_string($password);
$query = "SELECT * FROM login_details WHERE email ='$email' AND password ='$password'";

also dont use mysql_* as they are depracated.use PDO instead.

R R
  • 3,025
  • 2
  • 22
  • 42
-3

The manual for mysql_query tells you everything you need to know:

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

Abort your code and use PDO instead.

Failing that: make sure you've successfully opened a connection to a MySQL server, first. Then, make sure that mysql_query executes successfully.

$sql_query_run = mysql_query($query) or die (mysql_error());
Community
  • 1
  • 1
ta.speot.is
  • 26,445
  • 8
  • 64
  • 94