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
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

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.