A
Anonymous
Guest
I created a login page, but when I enter my username and password I am redirected to the login page as if the username and password are incorrect. What is wrong with my code?
Problem is at: http://martialartsupplystore.littlegd.com/catalog/admin/login_form.php
user: test
password: test
This is the code for the page you should go to when logged in:
Problem is at: http://martialartsupplystore.littlegd.com/catalog/admin/login_form.php
user: test
password: test
This is the code for the page you should go to when logged in:
Code:
<?php
//check for required fields from the form
if ((!$_POST[user]) || (!$_POST[password])) {
header("Location: login_form.php");
exit;
}
//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("mass",$conn) or die(mysql_error());
//create and issue the query
$sql = "select first_name from member where user =
'$_POST[user]' AND password = password('$_POST[password]')";
$result = mysql_query($sql,$conn) or die(mysql_error());
//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {
//if authorized, get the value of first_name
$first_name = mysql_result($result, 0, 'first_name');
//set authorization cookie
setcookie("auth", "1", 0, "/", "http://martialartsupplystore.littlegd.com", 0);
//prepare message for printing, and user menu
$msg = "<p>Welcome, $first_name!</p>";
} else {
//redirect back to login form if not authorized
head("Location: login_form.php");
exit;
}
?>