Jump to content

Recommended Posts

guys,

i need help, i have and admin page wherein it has 2 different kinds of user, namely admin and staff.
they login to the index page of the admin site
and after validation
for the admin it will lead him to homepage.php
for the staff if will lead him to homepage2.php

my problem is with the validation page.
i am getting error on line 36

below is my script. hope you can help me with this. thanks in advance!

A few questions:

With the query: SELECT * FROM users WHERE username='$username' AND password='$password'

Why do you check if multiple results returned? Should'nt there only be one result returned? Username should be a primary unique key right? So simply do:

if($login_check == 0) { //NOT LOGGED IN }
else { //LOGGED IN }

Second, in the following:

[code]
session_register('userid');
       $_SESSION['userid'] = $userid;
       session_register('username');
       $_SESSION['username'] = $username;
       session_register('special_user');
       $_SESSION['user_level'] = $user_level;
[/code]

Should'nt they be:

$_SESSION['userid'] = $row['userid'];
$_SESSION['username'] = $row['username'];
$_SESSION['user_level'] = $row['user_level'];


Thorpe:

Really, session_register() is not needed? I do the following in all my code.

session_register("session_id");
session_register("session_username");
$session_id = $row['id'];
$session_username = $_POST['employee_username'];
Because he does:

session_register('userid');
        $_SESSION['userid'] = $userid;
        session_register('username');
        $_SESSION['username'] = $username;
        session_register('special_user');
        $_SESSION['user_level'] = $user_level;

Where is $userid, $username, and $user_level defined? I beleive they are elements in the $row array, right? And, session_register is required to create a session.
He had allready extracted those variables from the $row array using...

[code=php:0]
foreach( $row AS $key => $val ){
    $$key = stripslashes( $val );
}
[/code]

And no. session_register() has long been depricated.

Anyway, pixeltrace... have you got your current code we can see? The error should be fixed with realjumpers suggestion.
Ohh, shintnaz, thorpe your right.

register_session() only works with register_globals on. What is the proper way to do it then? Is it simply like:

$_SESSION['session_id'] = $row['id'];
$_SESSION['username'] = $_POST['employee_username'];

Also read in php6 they removing register globals, I think that is bad decision. It should still be an option. Many applications are written assuming register globals.
[quote]this is what i did.... is this correct?[/quote]

Not really. What is this code meant to actually do? I meen, you have this line...

[code=php:0]
$login_check = mysql_num_rows($sql);
[/code]

but there is no query before it so its kinda pointless.

Also, as has been stated you are using while() loops that I believe should'nt be required. User names should be unique.
http://www.sinagtala.net/checkUser.phps

i was able to fix it somehow

but when i login using admin or staff userid...
its directing me to homepage.php

if i login using admin userid it should direct me to homepage.php

if i login using staff userid it should direct me to homepage2.php

what else is wrong in my codes?
this was in my code before

$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
$login_check = mysql_num_rows($sql);

this line is before

if($login_check == 0) { //NOT LOGGED IN }

what else needs to be fixed here?
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.