Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Junior Member
    Join Date
    Jul 2003
    Posts
    4
    Member #
    2015
    Could some one please help???

    I have a login script, which has a staff and student option.
    Once the user has logged in I would like to redirect the relevant user to the staff or student section on the website.

    I have been working on it for 2 days now and I really need some help.

    This is what I have got.

    1) MySQL DB with the following fields:
    ID
    username
    password
    url

    ---------------------------------------------------------------------
    2) --Login.php--

    <html>
    <head>
    <title>Login Page</title>
    </head>
    <body>

    <?php include("getresult.inc"); ?>

    Enter your login details you added on the previous page and test the login.<br>
    The success or failure will be shown above.

    <form ACTION="login.php" METHOD="POST">

    <table>
    <tr>
    <td>Username:</td>
    <td><p><input NAME="username" VALUE SIZE="8" MAXLENGTH="16"></td>
    </tr>
    <tr align="center">
    <td>Password:</td>
    <td><input type="password" name="password" size="8" maxlength="8"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input TYPE="submit" VALUE="Login"></td>
    </tr>
    </table>
    </form>

    </body>
    </html>

    ---------------------------------------------------------------------

    3) --getresult.inc--

    <?php

    if (isset($password)) // if a the password is set then the form has been submitted on login.php page
    {
    include("connect2db.php");
    $qstr = "SELECT * from members where username = '$username' and password = '$password'";

    $result = mysql_query($qstr);

    // check login info is correct
    if (mysql_num_rows($result)) echo "**Successful Login**";
    else echo "**Failed Login**";
    mysql_close();
    }
    else echo "**No login attempted**";

    ?>

    ---------------------------------------------------------------------

    4) --connect2db.php--

    <?php
    $mysql_database="DB"; // change to your own
    $mysql_username="name"; // change to your own
    $mysql_password="password"; // change to your own
    $link = mysql_connect("host",$mysql_username,$mysql_passwo rd) or die ("Unable to connect to SQL server");
    mysql_select_db($mysql_username,$link) or die ("Unable to select database");
    ?>

    ---------------------------------------------------------------------

    I am sorry if you feel that posting all the code is unnecessary, but I want to make sure that the person who is willing to help has every thing they need.

    Could someone please put me out of my misery????????

    LOL and Many thanks in advance.

  2.  

  3. #2
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Has what you have got so far working? I don't want to help you with the redirect code if that is not the problem yet.
    JR

  4. #3
    Member nepharo's Avatar
    Join Date
    Jun 2003
    Posts
    73
    Member #
    1729
    Yeah, is it working as jr said?
    You could put another colum in the db. Some thing along the line of a boolean 'staff'. If true then is a staff member. You could check for that field when the user logs in. I would also suggest to specifically check for all the fields before working with them 'cause the person could enter a password but not a username.
    I cannot self terminate, you must lower me into the fire.

  5. #4
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    Why have a URL field in the table along with the user info? Personally, I'd set up 2 tables. One that holds the IDs of students, another that holds the IDs of staff. It finds where they are, then pulls up the appropriate site for student/staff. Alternatively, you can have just a boolean field that is 1 if they're a staff member, 0 if they're a student.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  6. #5
    Junior Member
    Join Date
    Jul 2003
    Posts
    4
    Member #
    2015
    All code does work

    Hi JR and others,

    The code works fine for logging in and checking for current logged in status.

    It is just when the user is logged in; I can not get the URL from the DB to implement a redirect.

    As for the URL field in the DB, it seemed at the time the most appropriate way to store the data needed to retrieve the required URL result.

    I have not tried a Boolean check box?

    If someone could offer me some coded examples as a guide for me to follow that would be extremely appreciated.

    I do not expect you to do this for me but I really need some direction in achieving this.

    Thanks again for any knowledge shared on this matter
    Aaron :-)

  7. #6
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    If you have 1 staff page and 1 student page then you want to add a column called staff then add 1 for staff and 0 for student.

    Change this
    PHP Code:
    // check login info is correct
    if (mysql_num_rows($result)) echo "**Successful Login**";
    else echo 
    "**Failed Login**"

    to this
    PHP Code:
    if (mysql_num_rows($result)) {
        while (
    $member mysql_fetch_row($result) {
            if (
    member['[i]staff/student column name[/i]'] == 1) {
                
    header("location: $staff");
            } else {
                
    header("location: $students");
            }
        }
    } else {
        echo 
    "**Failed Login**"

    and add
    PHP Code:
    $staff '[i]staffpage[/i].php';
    $students '[i]studentspage[/i].php'
    somewhere above that code

    Should work, post if you have any probs
    JR

  8. #7
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    also i am no php genius, but i am not sure if this
    PHP Code:
    if (mysql_num_rows($result)) 
    is actually doing anything. I may be wrong but it might have to be something like this
    PHP Code:
    if (mysql_num_rows($result) == 1)

    or

    if (
    mysql_num_rows($result) != ''
    wait for somebody with more knowledge (or yourself) to give an answer to that though, i am not completely sure.
    JR

  9. #8
    Junior Member
    Join Date
    Jul 2003
    Posts
    4
    Member #
    2015
    HI JR,

    I am still working on editing the new code.

    This is what I have done so far:

    ----------------------------------------------------------

    <?php

    if (isset($password)) // if a the password is set then the form has been submitted on login.php page
    {

    $mysql_database="SPP_admin"; // change to your own
    $mysql_username="username"; // change to your own
    $mysql_password="password"; // change to your own

    $link = mysql_connect("mysql-server.ucl.ac.uk",$mysql_username,$mysql_password)
    or die ("Unable to connect to SQL server");

    mysql_select_db($mysql_username,$link)
    or die ("Unable to select database");

    $qstr = "SELECT id, password, username, member from SPP_admin where username = '$username' and password = '$password'";

    $staff = 'staffpage.php';
    $students = 'studentspage.php';

    $result = mysql_query($qstr)
    or die("Couldn't execute query.");

    // check login info is correct
    if (mysql_num_rows($result)) {
    while ($member = mysql_fetch_row($result)) {
    if (member['username'] == 1) {
    header("location: $staff");
    } else {
    header("location: $students");
    }
    }
    } else {
    echo "**Failed Login**";
    }
    mysql_close();
    }
    else echo "**No login attempted**";

    ?>

    When I get to the while statment it gives me a pharse error.

    If I change the while statment:

    --------------------------------------------------------------
    FROM THIS

    while ($member = mysql_fetch_row($result)) {
    if (member['username'] == 1) {
    header("location: $staff");
    --------------------------------------------------------------
    TO THIS

    while ($member = mysql_fetch_row($result)) {
    if ($member['username'] == 1) {
    header("location: $staff");
    --------------------------------------------------------------

    Then it parses the script but gives a header error.

    I have looked into the header error and I have managed to work out that any refference to header needs to be at the beginnnig of the script for it to parse.

    Is there a work around for this as it stands?

    Aaron

  10. #9
    Junior Member
    Join Date
    Jul 2003
    Posts
    4
    Member #
    2015
    HI JR,

    A little update.

    I have managed to get the script to redirect. Am still working on it but it seems to be coming along nicely.

    Thanks for your help. I am off on a little break now for 4 days, so if I do not reply to any messages, please excuse me.

    Thanks again, and when I get back I will finish the script and it will work as it was intended to.

    Aaron


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:33 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com