www.webdeveloper.com
Results 1 to 4 of 4

Thread: php session help

  1. #1
    Join Date
    Jul 2012
    Posts
    55

    php session help

    Hello, I'm trying to get a user from database users with admin field of Y, to be directed to page a, and admin field of N to go to page b. I'm failing at this.

    bunch of variables up here...

    $sql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password' AND admin='$admin' LIMIT 1";
    $run = mysql_query($sql);
    $count = mysql_num_rows($run);


    if ($count > 0) && ($admin = Y) {
    $_SESSION['user'] = $username;
    $_SESSION['admin'] = $admin;
    header('Location: admincp.php');
    exit();
    }

    elseif ($count > 0) && ($admin = N) {
    $_SESSION['user'] = $username;
    header('Location: membercp.php');
    exit();
    }

    else {
    header('Location: home.php');
    exit();
    }

    then admin Y page checks if session user and admin is filled
    and admin N page checks if session user is filled. The code on those pages are right(i think), but It's probably my method of going about this is wrong.

  2. #2
    Join Date
    Aug 2012
    Posts
    155
    The first glaring issue I see is that you are using one = instead of two (you need two to compare values, ie. 'is equal to') and you have not put your Y and N in quote marks (as they are not integers), they should be
    PHP Code:
    if ($count 0) && ($admin == 'Y')

    if (
    $count 0) && ($admin == 'N'
    However I also don't know where your $admin variable is being set and assigned a value so that could also be causing a problem.

  3. #3
    Join Date
    Jul 2012
    Posts
    55
    Thank you,

    and I wish to set the variable durring the query so I can keep track of it. $admin first apears here: AND admin='$admin' (durring the query)

    What would be the proper way of going about this?

  4. #4
    Join Date
    Aug 2012
    Posts
    155
    What you have in your query means that AND admin='The value assigned to the variable $admin', therefore a value has to have been assigned to the variable $admin before you can use it in your query.

    However, looking at your query you are actually trying to work out the value of admin stored in the database for the user who is logging in and therefore your query should just be
    PHP Code:
    $sql "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password' LIMIT 1"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles