i have done a login form but its giving error :9 can somwan help me

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<title>Login Panel</title>
</head>
<body>
<form action="login.php" method="POST">
Username : <input type="text" name="username" >
Password : <input type="text" name="password" >
<input type="submit" value="Login">
</form>
</body>
</html>

login.php

<?php
$username = $_POST['username'];
$password = $_POST['password'];
if($username&&$password)
{
$conect = mysql_connect("localhost","danvrajmas","nokia3110")or die("Error");
mysql_select_db("user")or die("Error");
$query = mysql_query("SELECT * FROM user WHERE username='$username'")or die("Error");
$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 "You're in !";	
}
else
   die("Incorect Password !");
}
else
   die("This user doesn't exist !");
}
else
 die("Enter a user name and password !");

?>

Recommended Answers

All 4 Replies

im gheting the Incorect password Error

Hey,
1. What is this "but its giving error :9"? error 9..what???

2.Have you tried with the correct username and password.If so provide a space in the if statement as(especially the "&&")

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

for me this is how i think the Your login system should be.

$username = $_POST['username'];
$password = $_POST['password'];
 if(($username)&&($password))
{
$conect = mysql_connect("localhost","danvrajmas","nokia3110")or die("Error");
mysql_select_db("user")or die("Error");
$query = mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password'")or die("Error");
$numrows = mysql_num_rows($query);

if ($numrows==1)
{

$row = mysql_fetch_assoc($query);
$dbusername = $row["username"];
$dbpassword = $row["password"];

echo "You're in !";	
}else{
echo"Error! Either pass or Username is incorect!if u are not member Consider to register";
}
 
}else{
die("Enter username and password fields shouldnot be empty !");

}

i dont see why You used the while loop,fetching a single profile info..
And why you are comparing the passwords after fetching the results.

also try to hide your login and passwords when sending online codes

$conect = mysql_connect("localhost","danvrajmas","nokia3110")or die("Error");

Thx im new in php and im Learnig :|

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.