Jump to content

[SOLVED] Log In Script - Need to log in using account number, instead of Email address


brainstorm

Recommended Posts

Hi All,

 

I'm using a log in script that logs you in using your email address and password. However, I need to change it so that the user logs in using their account number and password. The row for account number has been added to the DB and I've tried changing the variables to include the "account_num" field as oppose to the "user_email" field with no luck...It just gives me a "access denied" error message.

 

Below is the script as it originally was written (this one works just fine)...Can anyone provide me some advice as to how I can change this so the log in is based on "acoun_num" vs. "user_email"? Thanks!

 

Login script:

 

<?php
include 'dbc.php';

$user_email = mysql_real_escape_string($_POST['email']);

if ($_POST['Submit']=='Login')
{
$md5pass = md5($_POST['pwd']);
$sql = "SELECT id,user_email FROM users WHERE
            user_email = '$user_email' AND
            user_pwd = '$md5pass' AND user_activated='1'";

$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);

    if ( $num != 0 ) {

        // A matching row was found - the user is authenticated.
       session_start();
   list($user_id,$user_email) = mysql_fetch_row($result);
	// this sets variables in the session
	$_SESSION['user']= $user_email;


	if (isset($_GET['ret']) && !empty($_GET['ret']))
	{
	header("Location: $_GET[ret]");
	} else
	{
	header("Location: myaccount.php");
	}
	//echo "Logged in...";
	exit();
    }

header("Location: admin_login.php?msg=Invalid Login. Please try again.");
//echo "Error:";
exit();
}

?>

 

Form:

 

 <p>

<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>

<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td><form name="form1" method="post" action="">
<p> </p>
<p align="center">Email: 
<input name="email" type="text" id="email">
</p>
<p align="center"> Password: 
<input name="pwd" type="password" id="pwd">
</p>
<p align="center">
  <input type="submit" name="Submit" value="Login">
</p>
<p align="center"><a href="forgot.php">Forgot Password</a>
<br /><br />
<a href="admin_login.php">Admin Login</a></p>
</form></td>
</tr>
</table>
</p>

What gives you "access denied"?  The PHP script?  Is that the entire error?

 

Actually it was because I missed one of the "user_email" variables and it was still looking for an email address vs. the account number I was trying to put in...I added the variable "account_num" in it's place and now it works perfectly!

 

Thanks!

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.