Problem with PHP/mySQL login code


Posted on 16th Feb 2014 07:03 pm by admin

Hello,

There is an error in my login script and I can't figure out what it is...
I believe it might be my "SELECT" statement...

Can anyone help me?

Code: <?php
//define ('SASI Services Portal');

//check if user is logged in
$loggedin==0;
if(isset($_POST['username']))
{
$loggedin=FALSE; //the user is not currently logged in

//so, open the mysQL database

//create the connection
$con=mysql_connect("localhost", "xxxx", "xxxx");

if(!$con)
{
die('Could not connect: ' .mysql_error());
}

mysql_select_db("my_SASI", $con);

$result= mysql_query("SELECT * FROM logins, users WHERE logins.loginID=users.userID AND Email_Address='".$_POST['username']."' AND password='".$_POST['password']."' AND accessLevel=1");

while($row=mysql_fetch_array($result))
{
session_start(); //start a new session
$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];
$_SESSION['firstname']=$row['FirstName'];
$_SESSION['lastname']=$row['LastName'];
$_SESSION['accesslevel']=$row['accessLevel'];
$loggedin=TRUE;

}






}
if($loggedin && $_SESSION['accesslevel']==0)
{
header('Location: student_admin.php');
exit();

}
if($loggedin && $_SESSION['accesslevel']==1)
{
header('Location: teacher_admin.php');
exit();

}
mysql_close($con);
?>

No comments posted yet

Your Answer:

Login to answer
344 Like 40 Dislike
Previous forums Next forums
Other forums

Parse Error
Hi Guys,

I have a function in my class which returns a string link variable. The problem is i

PEAR in appliactiond development
When I was picking up PHP I went from procedural programming, fairly quickly into OOP, then after wr

Save file by click
Hello.
I'm not understand how to save file from page. I'd like make link to file with save abil

How to display random record from table?
I have the following code:

Code: <?php
$display_block .= "<input type=

How to secure my login data to my database?
Hi there,

It may be a stupid question but I don't know how to secure my login data to my data

SWF image using php?
Hello once again.

My latest en devour requires me to produce an image of a static .swf that i

Array becomes unset by itself?
Hi,

I have a bit of experience with PHP but not extensive. It seems I cannot store any items

Ariba 9r - SAP MM Integration
Hi experts,

The standard Ariba adapter for 9r creates a relationship between Cost Centers

Get word number x from string?
How can I use a function to loop through a string, and "have a look at" every word in the

Cursor statement failed with errors
Following statement failed with the errors.

cursor proj_cursor1 is (select projectID from

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash