pixelsoul
-
Posts
2 -
Joined
-
Last visited
Never
Posts posted by pixelsoul
-
-
what forum did you move this to??
I am trying to find out about this also and would like to see the reponses to this post. I have tried to search the forum but could not find it any where!
function not working properly?
in PHP Coding Help
Posted
[code]
<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>User Login</title>
</head>
<body>
<?php
function login_form(){
//function that when called outputs the login form
echo "<form action=\"index.php\" method=\"POST\"><h3>System Login</h3>User Name: <input type=\"text\" name=\"user_name\"><br>Password : <input type=\"password\" name=\"password\"><br><input type=\"submit\" name=\"submit\" value=\"Login\"><br></form>";
}
if (isset($_POST['username'])) {
$inputusername=$_POST['username'];
$inputpassword=$_POST['password'];
$host="";//mysql host
$user="";//mysql username
$pass="";//mysql password for the username
$database="";//name of the database
$connection=mysql_connect($host, $user, $pass) or die(mysql_error());//connect to db
$db=mysql_select_db($database, $connection) or die(mysql_error());//select database
$sql = "SELECT password FROM users WHERE username='$inputusername'";//the query
$result = mysql_query($sql) or die("Incorrect username - <a href=\"index.php\">try again</a>");//run the query, if it can't find a user output error message and link to try login again
$row=mysql_fetch_array($result);//get an array from the row
list($dbpassword)=$row;//get $dbpassword out of the array
if ($dbpassword == $inputpassword) {//if the password they entered is correct for that username
//Logged in
$_SESSION['username'] = $username;//start session for user to allow access to protected pages
echo "You are now logged in";
} else {
echo "Incorrect password<br/>";
login_form();
}
}
?>
</body>
</html>
[/code]
thanks for the help.