Jump to content

New to php... login doesnt work


Rifts

Recommended Posts

Hey guys, I'm pretty new to php.. I downloaded a little php login form.. but its not working.

 

when i hit submit instead of going to the members-index.php site it just reloads the normal index and changes the url bar to this http://localhost/homepage/?user=admin&password=pass&Submit=Login#

 

i'm not really sure what other information to give you... let me know what else you need

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/176532-new-to-php-login-doesnt-work/
Share on other sites

ok here is the login form code in my index.html

<center>
        <div id="login">
<form id="loginForm" method="post" action="login-exec.php">
  Client ID: <br /><input type="text" class="theInput" name="user" /> <br />
  Password: <br /><input type="password" class="theInput" name="password" /> <br />           		     
       <input type="submit" name="Submit" class="theSubmit" value="Login" />
	</form>
	</center>

 

and here is the login-exec.php  (I think when I hit submit its not "activating" the login-exec.php)

 

<?php
//Start session
session_start();

//Include database connection details
require_once('config.php');

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}

//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
$login = clean($_POST['login']);
$password = clean($_POST['password']);

//Input Validations
if($login == '') {
	$errmsg_arr[] = 'Login ID 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 members WHERE login='$login' AND passwd='".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();
		$member = mysql_fetch_assoc($result);
		$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
		$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
		$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
		session_write_close();
		header("location: http://localhost/homepage/member-index.php");
		exit();
	}else {
		//Login failed
		header("location: login-failed.php");
		exit();
	}
}else {
	die("Query failed");
}
?>

 

thanks lemme know what else you might need

 

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.