Jump to content

Recommended Posts

This code tests my login form. It is connecting to the database but it is allowing the user to go to the profile page whether or not the username and password are correct.

I have 4 different types of users that need to access different areas of the site. ie if level = 1 go to manager.php etc

Please help

 

 

 

<?php

session_start();

$_SESSION['username'] = @$_POST['username'];

$_SESSION['pass'] = @$_POST['pass'];

$username = @$_POST['username'];

$pass= @$_POST['pass'];

 

$conn = new COM('ADODB.Connection') or die('Could not make conn');

$rs = new COM('ADODB.Recordset') or die('Coult not make rs');

 

$connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\wamp\www\pro\employees.mdb";

 

 

$conn->Open($connstring);

if (!$conn)

  {exit("Connection Failed: " . $conn);}

$sql="SELECT Username, Password

FROM Details

WHERE Username = '$username' AND  Password= '$pass'";

$rs->Open($sql, $conn);

 

if (!$rs->EOF)

{

if ( $rs->Fields["Username"]->value

&& $rs->Fields["Username"]->value == $email

&& $rs->Fields["Password"]->value

&& $rs->Fields["Password"]->value == $pass

)

{

$_SESSION["error"] = "login Error as $username. " ;

header("Location: index.php?error=Sign in error");

}

}

else

{

$_SESSION["auth"] = $username;

// Relocate to the logged-in page

header("Location: profile.php");

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/97718-need-login-if-statements-please-help/
Share on other sites

untested but may help ( i don't use access much) also check the comments about level field (change to the correct field name)

 

<?php
session_start();
$_SESSION['username'] = @$_POST['username'];
$_SESSION['pass'] = @$_POST['pass'];
$username = $_POST['username'];
$pass= $_POST['pass'];

$conn = new COM('ADODB.Connection') or die('Could not make conn');
$rs = new COM('ADODB.Recordset') or die('Coult not make rs');

$connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\wamp\www\pro\employees.mdb";


$conn->Open($connstring);
if (!$conn){
exit("Connection Failed: " . $conn);
}
//Add field Level
$sql="SELECT Username, Password, Level
FROM Details
WHERE Username = '$username' AND  Password= '$pass'";
$rs->Open($sql, $conn);

$page = "index.php?error=Sign in error";
if($rs->EOF)
{
$_SESSION["error"] = "login Error as $username. " ;
}else{	
$_SESSION["auth"] = $username;
$level = $rs->Fields['Level']->Value; //Field Level
switch($level)
{
	case "1":
		$page = "profile.php";
	break;
	case "2":
		$page = "profile2.php"; // whatever
	break;
}
}
// Relocate to the logged-in page
header("Location: $page");
?>

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.