simcoweb Posted July 8, 2007 Share Posted July 8, 2007 I've tried to streamline this login script as much as possible. The problem is It just doesn't want to recognize a legit login. I'm MD5'ing the password when they create their username/password during registration. Then i'm simply checking it against the database. If successful it should take them to the search.php page. Instead it goes to the error.htm page which is the 'fail' page. Here's the code: <?php ob_start(); session_start(); // Seattle Viet Homes customer login // Turn on magic quotes to prevent SQL injection attacks if(!get_magic_quotes_gpc()) set_magic_quotes_runtime(1); // check for form submission if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['Username']) || empty($_POST['Password'])) { $errors[] = "<h3>Error!</h3><p><font face='Verdana' size='2'>You must complete the username and password fields. Please try again"; } if (!$errors){ include 'db_config2.inc.php'; $username = $_POST['Username']; $password = $_POST['Password']; $password = md5($password); // validate username and password against the database $sql = "SELECT * FROM users WHERE Username='$username' AND Password='$password' AND status='1'"; $results = mysql_query($sql, $dbc) or die(mysql_error()); if(mysql_num_rows($results) == 1) { $_SESSION['searchlog']; header("Location: search.php"); //exit; } else { header("Location: error.htm"); } } } ?> Link to comment https://forums.phpfreaks.com/topic/58917-login-script-has-me-baffled/ Share on other sites More sharing options...
vbnullchar Posted July 8, 2007 Share Posted July 8, 2007 you misplaced a closing "}" bracket.. i fixed it but i havent tried it yet, please try <?php ob_start(); session_start(); // Seattle Viet Homes customer login // Turn on magic quotes to prevent SQL injection attacks if(!get_magic_quotes_gpc()) set_magic_quotes_runtime(1); // check for form submission if (isset($_POST['submitted'])) { if (empty($_POST['Username']) || empty($_POST['Password'])) { $errors[] = "<h3>Error!</h3><p><font face='Verdana' size='2'>You must complete the username and password fields. Please try again"; } if (is_array($errors)){ include 'db_config2.inc.php'; $username = $_POST['Username']; $password = $_POST['Password']; $password = md5($password); // validate username and password against the database $sql = "SELECT * FROM users WHERE Username='$username' AND Password='$password' AND status='1'"; $results = mysql_query($sql, $dbc) or die(mysql_error()); if(mysql_num_rows($results) == 1) { $_SESSION['searchlog']; header("Location: search.php"); //exit; } else { header("Location: error.htm"); } } } ?> Link to comment https://forums.phpfreaks.com/topic/58917-login-script-has-me-baffled/#findComment-292386 Share on other sites More sharing options...
simcoweb Posted July 8, 2007 Author Share Posted July 8, 2007 Thanks for the post. I tried your revisions but all it produces is a blank page. I've seen this before and it had to do with the MD5 password. Basically I have my form pointing to your script. When submitted it goes to the script but the page is blank. It's like it fails without actually producing an error. Baffling. Link to comment https://forums.phpfreaks.com/topic/58917-login-script-has-me-baffled/#findComment-292389 Share on other sites More sharing options...
GingerRobot Posted July 8, 2007 Share Posted July 8, 2007 Surely this line here: if (is_array($errors)){ Should be: if (!is_array($errors)){ After all, you only want to execute the next bit of code if there are no errors. Link to comment https://forums.phpfreaks.com/topic/58917-login-script-has-me-baffled/#findComment-292394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.