Jump to content

What I am doing Wrong? mysql num row error


princeofpersia

Recommended Posts

Hi guys

 

I have a code where users can login, I have checked all the database fields, variables etc and they are all correct. I have the code below and I will appreciate it if you help me to see what is wrong?

 

<?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>
<?php include'includes/db/db.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JSA Dashboard - Login</title>
<link href="styles/layout.css" rel="stylesheet" type="text/css" />
<link href="styles/login.css" rel="stylesheet" type="text/css" />
<!-- Theme Start -->
<link href="themes/blue/styles.css" rel="stylesheet" type="text/css" />
<!-- Theme End -->

</head>
<body>

<div id="logincontainer">
<?php
$session_email = $_SESSION['email'];
if ($_POST['login'])
{
$email=mysql_real_escape_string(strip_tags($_POST['email']));	
$enteredpassword=mysql_real_escape_string(strip_tags($_POST['password']));	

if(!$email || !$enteredpassword) {echo "<div class='status error'><p class='closestatus'><a href='' title='Close'>x</a></p>Please enter both email and password, this message appears when you have not entered your email or password to login!</div>";}

   else
   {
$password=md5($enteredpassword);
$getuser=mysql_query("SELECT * FROM users WHERE $email='email'");
while($row = mysql_fetch_array($getuser))
{
$dbemail=$row['email'];
$dbpassword=$row['password'];
}
if (mysql_num_rows($getuser)==0)	   
{echo "<div class='status error'><p class='closestatus'><a href='' title='Close'>x</a></p>This user doesn't exist</div>";}

else

{


if ($dbpassword !=$password){echo "<div class='status error'><p class='closestatus'><a href='' title='Close'>x</a></p>Password is incorrect!</div>";}

else

{
    $_SESSION['email']=$email; //assign session
           header("Location: main.php"); //refresh	
}




}
   
   
   
   
   }




}




?>
    	<div id="loginbox">
        	<div id="loginheader">
            	<img src="themes/blue/img/cp_logo_login.png" alt="Control Panel Login" />
            </div>
            <div id="innerlogin">
            	<form action="" name="login" method='POST'>
                	<p>Enter your Email:</p>
                	<input type="text" class="logininput" name="email"/>
                    <p>Enter your password:</p>
                	<input type="password" class="logininput" name="password"/>
                   
                   	<input type="submit" class="loginbtn" value="Login" name="login"/><br />
                    
                </form>
            </div>
        </div>
        <img src="img/login_fade.png" alt="Fade" />
    </div>
</body>
</html>

btw this is the error i get

 

Notice: Undefined index: email in /Users/roozbehj/Sites/jsa/dashboard/index.php on line 44

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Users/abc/Sites/jsa/dashboard/index.php on line 56

 

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /Users/abc/Sites/jsa/dashboard/index.php on line 61

there are a couple of errors that I notice when looking at your code..

 

1. you are receving the notice for the undefined index because you $_POST['email'] has not been processed. This is probably because you have not submitted the form yet. To get rid of this error simply change this

if(!$email || !$enteredpassword)

to

if(!isset($email) || !$enteredpassword)

the isset() function will check if the index has been set, if it hasn't, it will not give you that notice.

 

2. you are receiving the mysl_fetch_array() and mysql_num_rows errors because your mysql_query is incorrect. by writing this

$getuser=mysql_query("SELECT * FROM users WHERE $email='email'");

you are setting the column_name to your variable which is not what you want to do...try this instead

$getuser=mysql_query("SELECT * FROM users WHERE email='$email'");

this is assuming that your column_name is email..if you have any more problems let us know

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.