herghost Posted April 9, 2009 Share Posted April 9, 2009 Hi all, Wonder if anyone can spot whats gone wrong here! I have a simple login form, which looks like this: <?php session_start();?> <form id="loginForm" name="loginForm" method="post" action="login-exec.php"> <table width="255" height="98" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="112"><b>Login</b></td> <td width="188"><input name="login" type="text" class="textfield" id="login" /></td> </tr> <tr> <td><b>Password</b></td> <td><input name="password" type="password" class="textfield" id="password" /></td> </tr> </table> <input type="image" src="buttons/login.jpg" height="78" width="164" name="Submit" value="Login" /> </form> which leads to this: <?php //Start session session_start(); //Include database connection details require_once('include/database.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $username = clean($_POST['username']); $password = clean($_POST['password']); //Input Validations if($username == '') { $errmsg_arr[] = 'Username missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM user WHERE username='$username' AND password='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $user = mysql_fetch_assoc($result); $_SESSION['SESS_USERID'] = $user['userid']; $_SESSION['SESS_BANDNAME'] = $user['bandname']; session_write_close(); header("location: member_home.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> my database is called user and is structured userid, bandname, username, password the problem is thus, when you try to login you get redirected to login-form.php which means the validation failed on username and password, but I cant see why! Anyone spot it?! Thanks Link to comment https://forums.phpfreaks.com/topic/153387-solved-login-form-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2009 Share Posted April 9, 2009 Your form field is named "login", not "username" Are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that you get immediate feedback for things like $_POST variables that don't exist? Link to comment https://forums.phpfreaks.com/topic/153387-solved-login-form-help/#findComment-805851 Share on other sites More sharing options...
herghost Posted April 9, 2009 Author Share Posted April 9, 2009 Thanks for that, I have always had display errors on, but until about 3 minutes ago I did not know about error_reporting set to E_ALL, I have now turned this on in php.ini Again, many thanks! Link to comment https://forums.phpfreaks.com/topic/153387-solved-login-form-help/#findComment-805854 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.