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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.