Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.