I'm pretty sure I have this coded correctly, but I'm not entirely sure. This is for a simple login form, and I keep getting "Invalid User" returned whenever I try to login.
I'm checking MySQL database, and the entry is there. Here is my code in log.php:
<?php
session_name("MyLogin");
session_start();
if($_GET['action'] == "login") {
$conn = mysql_connect("host","username","password"); // your MySQL connection data
$db = mysql_select_db("database"); //put your database name in here
$name = $_POST['user'];
$q_user = mysql_query("SELECT * FROM USERS WHERE login='$name'");
if(mysql_num_rows($q_user) == 1) {
$query = mysql_query(" SELECT * FROM USERS WHERE login='$name'");
$data = mysql_fetch_array($query);
if($_POST['pwd'] == $data['password']) {
session_register("name");
header("Location: index.html"); // success page. put the URL you want
exit;
} else {
header("Location: login.php?login=failed&cause=".urlencode('Wrong Password'));
exit;
}
} else {
header("Location: login.php?login=failed&cause=".urlencode('Invalid User'));
exit;
}
}
// if the session is not registered
if(session_is_registered("name") == false) {
header("Location: login.php");
}
?>