Can anyone see a problem with this? - Newb Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fireballgames
Forum Newbie
Posts: 6
Joined: Sun Dec 21, 2008 1:04 pm

Can anyone see a problem with this? - Newb Question

Post by fireballgames »

Thank you for looking at this thread. I'm having a problem with a user login system, there is a table in my database with Access Levels in it. From a login check (Which works) I want to get the access level and turn it into a cookie to give the user access to different parts of my website. The error I get is that all users, despite different access levels, get turned into "Users".
I believe I've gone wrong in this one part of code:

Code: Select all

 
[color=#40FF00]//Access Levels---------------[/color]
$sql1="SELECT Level_access, Username, Password FROM $tbl_name WHERE Username='$Username' and Password='$Password'";
$reesult=mysql_query($sql1);
if($reesult==2){
setcookie("admin", $Username, time()+3600);
}
elseif($reesult1==1){
setcookie("donator", $Username, time()+3600);
}
else{
setcookie("user", $Username, time()+3600);
}
 
Thanks again for reading.
Last edited by fireballgames on Sun Dec 21, 2008 3:51 pm, edited 3 times in total.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Can anyone see a problem with this? - Newb Question

Post by jaoudestudios »

I think you are over complaining the matter.

Using sessions would be easier.

When the user logs in get the user level/role then and just keep checking that.
fireballgames
Forum Newbie
Posts: 6
Joined: Sun Dec 21, 2008 1:04 pm

Re: Can anyone see a problem with this? - Newb Question

Post by fireballgames »

I did try sessions but they didn't stay. I wasn't able to access my exclusive pages.
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Can anyone see a problem with this? - Newb Question

Post by mmj »

[quote]

Code: Select all

$seql="SELECT Level_access FROM $tbl_name WHERE Username='$Username' and Password='$Password'";
$reesult=mysql_query($sql1);
[quote]

Unless you set $sql1 in a different location thats your problem.
fireballgames
Forum Newbie
Posts: 6
Joined: Sun Dec 21, 2008 1:04 pm

Re: Can anyone see a problem with this? - Newb Question

Post by fireballgames »

Thanks, that isn't the problem though :cry:
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Re: Can anyone see a problem with this? - Newb Question

Post by wasir »

try this...

Code: Select all

$seql="SELECT Level_access, Username, Password FROM $tbl_name WHERE Username='$Username' and Password='$Password'";
$reesult=mysql_query($sql1);
paul00
Forum Newbie
Posts: 13
Joined: Sat Dec 20, 2008 2:54 pm

Re: Can anyone see a problem with this? - Newb Question

Post by paul00 »

Or better this

Code: Select all

 
$sql1="SELECT Level_access, Username, Password FROM $tbl_name WHERE Username='$Username' and Password='$Password'";
$reesult=mysql_query($sql1);
 
fireballgames
Forum Newbie
Posts: 6
Joined: Sun Dec 21, 2008 1:04 pm

Re: Can anyone see a problem with this? - Newb Question

Post by fireballgames »

Nope, still the same :( Thank you very much for attempting though
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Can anyone see a problem with this? - Newb Question

Post by jaoudestudios »

Did you have session_start() on your exclusive page?

You have no protection on your mysql queries from injection!

Post your database schema, then we can see what is wrong with the query - remember it is case sensitive.
fireballgames
Forum Newbie
Posts: 6
Joined: Sun Dec 21, 2008 1:04 pm

Re: Can anyone see a problem with this? - Newb Question

Post by fireballgames »

http://pastebin.ca/1291049 - My whole checklogin file

and how do I get a schema of the database from PHPMyAdmin?
fireballgames
Forum Newbie
Posts: 6
Joined: Sun Dec 21, 2008 1:04 pm

Re: Can anyone see a problem with this? - Newb Question

Post by fireballgames »

Infact - Close this plz :p I've seen another login script with exactly what I want: http://www.evolt.org/PHP-Login-System-w ... n-Features
Post Reply