0

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 !");

?>
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by dan1992
0

im gheting the Incorect password Error

Edited by dan1992: n/a

0

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)
0

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");

Edited by mrcniceguy: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.