I'm creating a login form that, when log in is clicked, should take you to my home.php page. However, if I put in the correct username and password and click login, it just refreshes the page and does not go to home.php
I'm thinking the error could be in any one of these bits of code or form.
This is from index.php
<?php // Login Script if (isset($_POST["user_login"]) && isset($_POST["password_login"])) { $user_login = preg_replace('#[^A-Za-z0-9]#i', '', $POST["user_login"]); // filter all characters but numbers and letters $password_login = preg_replace('#[^A-Za-z0-9]#i', '', $POST["password_login"]); //filter all characters but numbers and letters $sql = mysql_query("SELECT id FROM users WHERE username='$user_login' AND password='$password_login' LIMIT 1"); // query the user // check for their existance $userCount = mysql_num_rows($sql); // count the number of rows if ($userCount == 1) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; } $_SESSION["id"]= $id; $_SESSION["user_login"] = $user_login; $_SESSION["password_login"] = $password_login; header("location: index.php"); exit(); } else { echo 'The username or password is incorrect - Try again.'; exit(); } } ?>
<form action="index.php" method="post" name="form1" id="form1"> <input type="text" size="25" name="user_login" placeholder="Username" /><br /> <input type="password" size="25" name="user_password" placeholder="Password" /><br /> <input type="submit" name="button" id="button" value="Login" /> </form>
And this, so far, is my entire home.php
<?php session_start(); $user = $_SESSION["user_login"]; // If the user is not logged in if (!isset($_SESSION["user_login"])) { header("Location: index.php"); exit(); } else { // If the user is logged in echo "Hello, $user! Welcome to your homepage! <a href=\"logout.php\">Sign out</a> "; } ?>