please see the code below. I'm not able to figure out why it is showing error.
Have colored the area where showing error:
-------------------------------------------------------------------------
<html>
<head>
<title>Login.php</title>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
$query="mysql_select_db(login)";
mysql_query($query);
$username=$_POST['username'];
$password=md5($_POST['password']);
$chk_user="select name for users where username='$username'";
$user_exist=mysql_num_rows($chk_user);
if($user_exist != 1)
{
echo "Incorrect login";
include "login.html";
exit();
}
else
{
echo "login successfull";
}
?>
</body></html>
----------------------------------------------
saying incorrect use of mysql_num_rows,
and not accepting any username and password, always show incorrect login
P.S. : Attaching other related php and html files
What is wrong with this code...please help
Moderator: General Moderators
What is wrong with this code...please help
- Attachments
-
- 1.rar
- (1.78 KiB) Downloaded 2 times
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: What is wrong with this code...please help
Code: Select all
$con=mysql_connect("localhost","root","");
mysql_select_db(login);
$username=$_POST['username'];
$password=md5($_POST['password']);
$chk_user="select name for users where username='$username'";
$userQueryResult = mysql_query($chk_user);
$user_exist = mysql_num_rows($userQueryResult);
Re: What is wrong with this code...please help
thank you mark,
but still the same problem is occuring.
it gives this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Task1_15June\login.php on line 21
----------------------------------------
code i used:
<html>
<head>
<title>Login.php</title>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db(login);
$username=$_POST['username'];
$password=md5($_POST['password']);
$chk_user="select name for users where username='$username'";
$userQueryResult = mysql_query($chk_user);
$user_exist = mysql_num_rows($userQueryResult);
if($user_exist != 1)
{
echo "Incorrect login";
include "login.html";
exit();
}
else
{
echo "login successfull";
}
?>
</body></html>
but still the same problem is occuring.
it gives this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Task1_15June\login.php on line 21
----------------------------------------
code i used:
<html>
<head>
<title>Login.php</title>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db(login);
$username=$_POST['username'];
$password=md5($_POST['password']);
$chk_user="select name for users where username='$username'";
$userQueryResult = mysql_query($chk_user);
$user_exist = mysql_num_rows($userQueryResult);
if($user_exist != 1)
{
echo "Incorrect login";
include "login.html";
exit();
}
else
{
echo "login successfull";
}
?>
</body></html>
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: What is wrong with this code...please help
You query is wrong.
Like Mark Baker said dont forget to filter $username from mysql injection.
It should be...select name for users where username='$username'
Code: Select all
SELECT name FROM users WHERE username='$username'Re: What is wrong with this code...please help
Damn thank you yaar