Jump to content

User and Administration Login Page


anton_1

Recommended Posts

<?php

$host=""; // Host name

$username=""; // Mysql username

$password=""; // Mysql password

$db_name="helpdesk"; // Database name

$tbl_name="users"; // Table name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// username and password sent from form

$barcodeID=$_POST['barcode'];

 

 

 

// To protect MySQL injection (more detail about MySQL injection)

$barcodeID = stripslashes($barcodeID);

$barcodeID = mysql_real_escape_string($barcodeID);

 

 

$sql="SELECT * FROM $tbl_name WHERE BarcodeID='$barcodeID'";

 

 

 

 

$result=mysql_query($sql);

 

$isAdmin = mysql_fetch_row($result);

 

 

if ($result['Priority'] = "Admin")

{

header("location:AdminSection.php");

}

else                                                                              //do I have something missing here?

{

 

header("location:index.php");

 

}

 

 

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

 

// If result matched $myusername and $mypassword, table row must be 1 row

 

if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

$_SESSION['barcode'] = $barcodeSession;

$_SESSION['userlevel'] = $row['Priority'];

 

if($row['userlevel'] == "Admin") {

header("location:AdminSection.php");

}else{

header("location:index.php");

}

 

 

 

header("location:LoggedIn.php");

}

else {

header("location:index.php");

}

?>

 

 

 

 

When a user has been entered into the database with their priority set to Admin, it will no recognise it?

 

Any help is apprectiated

 

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/259741-user-and-administration-login-page/
Share on other sites

this

$isAdmin = mysql_fetch_row($result);
if ($result['Priority'] = "Admin")

 

needs to be

 

$isAdmin = mysql_fetch_array($result);
if ($isAdmin['Priority'] == "Admin")

 

EDIT: just picked up on the other issue with mysql_fetch_row, that returns the row in an array such as $isAdmin[0], $isAdmin[1] etc

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.