PDA

View Full Version : Login Boolean error



keyboard
08-12-2011, 08:46 PM
Hello everyone,

Somewhere on this page it is giving this error


( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\messaging2\Login2.php on line 18
Call Stack
# Time Memory Function Location
1 0.0004 375824 {main}( ) ..\Login2.php:0
2 0.0052 383328 mysql_num_rows ( ) ..\Login2.php:18

( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\messaging2\Login2.php on line 25
Call Stack
# Time Memory Function Location
1 0.0004 375824 {main}( ) ..\Login2.php:0
2 0.0055 383496 mysql_num_rows ( ) ..\Login2.php:25




<?php
session_start();
require_once 'database.php';

$username = $_POST['user'];
$escaped_username = mysql_real_escape_string($username);
$md5_password = md5($_POST['pass']);

$queryN = mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND
level='1'");#This variable will check if the user is a level 1 user (Normal User)
$queryA = mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND
level='9'");#This variable will check if the user is a level 9 user (Admin User)


if(mysql_num_rows($queryN) == 1)
{
$resultN = mysql_fetch_assoc($queryN);
$_SESSION['user'] = $_POST['user'];
header("location:Index.php");
}

elseif(mysql_num_rows($queryA) == 1)
{
$resultA = mysql_fetch_assoc($queryA);
$_SESSION['admin'] = $_POST['user'];
header("location:index.php");
}

else{
echo "Wrong Username or Password";
}
?>
<form name="back" method="post" action="login.php">
<input type="submit" name="back" id="back" value="Back to Home">

Any help?

JShor
08-13-2011, 02:01 AM
I'm almost positive that you have some SQL syntax error that is causing all of your queries to return false.

Try adding or die(mysql_error()) at the end of your mysql_query() functions. That will return MySQL errors if they occur. Then we can diagnose the problem.

Example:



$queryN = mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND
level='1'") or die(mysql_error());#This variable will check if the user is a level 1 user (Normal User)
$queryA = mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND
level='9'") or die(mysql_error());#This variable will check if the user is a level 9 user (Admin User)



Btw, you've already had a very similar error here:
http://www.dynamicdrive.com/forums/showthread.php?p=257873

mysql_query() always returns a boolean result of false when query errors occur.

JShor
08-13-2011, 02:01 AM
And I gave the same advice as before and it eventually led to you solving your problem. ;)