jukie Posted August 12, 2013 Share Posted August 12, 2013 (edited) Hi I have developed a register form and a login form, register form is working but the login form is not working. login form. The login check just takes me back to the index page instead of mybookmarks.php. Can anyone see the issue in these codes? <form id="form1" action="logincheck.php" id="op" method="post"> <fieldset> <legend>Get On This Login</legend> <input type ="hidden" name="submitted" id="submitted" value="1"/> <label for='Username' >UserName</label> <input type='text' name='Username' id='Username' maxlength="50" /> <label for='Password' >Password</label> <input type='password' name='Password' id='Password' maxlength="50" /><br> <input type='submit' name='Submit' value='Login' /> </fieldset> </form> logincheck.php <?php session_start(); // dBase file include "connection.php"; // Inialize session session_start(); // Include database connection settings // Retrieve username and password from database according to user's input $login = mysql_query("SELECT * FROM members WHERE (Username = '" . mysql_real_escape_string($_POST['Username']) . "') and (Password = '" . mysql_real_escape_string(md5($_POST['Password'])) . "')"); // Check username and password match if (mysql_num_rows($login) == 1) { // Set username session variable $_SESSION['Username'] = $_POST['Username']; // Jump to secured page header('Location: mybookmarks.php'); } else { // Jump to login page header('Location: index.php'); } ?> I have added the register connection incase this can help solve the issue // dBase file include "connection.php"; //retrieving data from form $Username =$_POST ['Username']; $emailaddress =$_POST ['emailaddress']; $FirstName = $_POST ['FirstName']; $Password =$_POST ['Password']; //Protect from SQL Injection $Username = mysql_real_escape_string($Username); $emailaddress = mysql_real_escape_string($emailaddress); $FirstName= mysql_real_escape_string($FirstName); $Password = mysql_real_escape_string($Password); //hash the password $Password = md5($pword); $query = "INSERT INTO members( Username, Password, emailaddress, FirstName) VALUES ('$Username', '$Password','$emailaddress', '$FirstName')"; $sucess = mysql_query($query); if ($sucess) header("Location: index.php"); mysql_close($conn); Thank you for reading. Edited August 12, 2013 by jukie Quote Link to comment Share on other sites More sharing options...
jukie Posted August 12, 2013 Author Share Posted August 12, 2013 Sorry, I have sorted it out, I seen the error right away after reading the post, it was the hash part $Password = md5($pword); its should have been password not pword, don't know why I couldn't see this in the editor tho. sorry Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.