PDA

View Full Version : login.php help


jaspindermukar
05-27-2012, 01:37 AM
I am creating login form for first time and struck with following code:
<?php


session_start();

$username = $_POST['username'];

$password = $_POST['password'];


if($username&&$password)

{
$connect =mysql_connect("mysql10.000webhost.com","a9714196_jas","bawamano83")or die ("couldnt connect to database");


mysql_select_db("a9714196_jas") or die ("coulnt find database");

$query = mysql_query("SELECT * FROM 'user' WHERE username = '$username'" );

$numrows = mysql_num_rows ($query);

if($numrows !=0)

{

while($row =mysql_fetch_assoc($query));

{

$dbusername = $row['username'];
$dbpassword = $row['password'];



}


if ($username==$dbusername&&$password==$dbpassword)

{

echo "Login successful.<a href='membersarea.php'>Click here to enter the members area </a>";

$_SESSION ['username']=$dbusername;





}
else

echo" Incorrect password";

}
else
die(" That username doesnot exist");




}

else

die("Please enter a username and password");





?>

The error message that I am getting is
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9714196/public_html/login.php on line 21

davidj
05-27-2012, 08:45 PM
Make sure your SQL is correct. Your tables are spelt correctly and are the correct case etc...

SELECT * FROM 'user' WHERE username = '$username'

edbr
05-28-2012, 02:59 AM
seems not to like if($numrows !=0)
try


if ($numrows > 0) {