Jump to content

login script has me baffled


simcoweb

Recommended Posts

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

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");
	}
}
}
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.