Jump to content

mysql_num_rows() ERROR


pranshu82202

Recommended Posts

Here is my CODE which is showing some error:

 

<?php
include('dbcon.php');
session_start();
$usname=$_POST['usname'];
$password=$_POST['password'];
$usname = stripslashes($usname);
$password = stripslashes($password);
$usname = mysql_real_escape_string($usname);
$password = mysql_real_escape_string($password); 
$check="y";
$sql = "select * from usname where usname='$usname' and password='$password'"; 
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
$sqlq = "select * from usname where usname='$usname' and password='$password' and check='$check'"; 
$resultq=mysql_query($sqlq);
$countq=mysql_num_rows($resultq);
if($countq==1)
{$_SESSION['usname']=$usname;
header('location:fire.php');}
else
{$_SESSION['status']="Admin Didnt grant you the permission to access the things";
header('location:index.php');}
}
else
{$_SESSION['status']="Wrong username and password";
header('location:index.php');}

die(" ");
?>

 

 

And here are the ERRORS when the username and passwords are correct but the check is not equal to 'y'....

 

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\money\verify.php on line 18

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\money\verify.php:18) in C:\xampp\htdocs\money\verify.php on line 24

 

Please tell me where is the mistake........... :(

Link to comment
https://forums.phpfreaks.com/topic/252570-mysql_num_rows-error/
Share on other sites

'password' is reserved word for MySQL, that's why use special letters/quotes (sorry, I don't know exact name for it :))

 

$sql = "select * from `usname` where `usname`='$usname' and `password`='$password'";

 

Also you would better use it for all: table names and column names. I'd recommend to don't use reserved words for column names at all.

 

PS. "Cannot modify header location..." - you get it because your script print some letters (error message about SQL error) before you try to use function header(...). Solve your SQL problem and then the second problem would be solved automatically.

'password' is not a  reserved word in MySQL (see here for full list).

 

You need to handle errors that could be returned from the query. Change any calls to:

 

mysql_query(...) or trigger_error(mysql_error(), E_USER_ERROR);

 

That will trigger a fatal error explaining the problem.

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.