www.webdeveloper.com
Results 1 to 10 of 10

Thread: I cannot get my page to display user information after they logged in. Help, please?

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Location
    Indiana
    Posts
    2

    I cannot get my page to display user information after they logged in. Help, please?

    I am new to PHP/MYSQL. The database works totally fine. I have a username, password, first, and last name field in my database currently. The log in works perfectly fine. I have all the statements needed and whatnot and my code validates whether or not I was able to log in. Here's my predicament...

    My form uses the POST method to retrieve the username/password and blah blah blah. I can have it display the username on any other pages by using the session cookies and whatnot. I just need to know how to access my first and last name information.

    For example. When the user logs in and they go to the next page, I want it to say: Welcome, Joe Blah. The text, Joe Blah, isn't inputted into the form or submitted any way. It's located IN the database. I just don't know how to access it...




    Once again, I'm sorry if some of the terms I used were incorrect. I actually JUST learned how to do this from a good friend of mine who is a web developer. I just need to know a little bit more. I'm catching on pretty well...I just can't seem to find what I'm looking for. I've browsed the internet an hour or so prior to this, and everything that has to do with displaying the user's info has to do with the POST method and they just re-display it on a different page.

    Well, thanks again!



    - Tim

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,327
    When you do the login, you can add any columns you want to the query you use to validate the login. If it's successful, store that data in the $_SESSION array with whatever else you are already storing to indicate that the user is logged in.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2009
    Location
    Indiana
    Posts
    2
    Ah, I see. Logically, I thought that would be a good idea; however, I'm not sure what I'd exactly write..? Like, the proper syntax and whatnot. I'm still browsing and finding coding examples. Bare with me...I'm learning quick for only being into this for less than 12 hours.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,327
    Can you show us the code you're using now (within [php]...[/php] tags) to do the login processing?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Sep 2011
    Posts
    6

    Same Problem

    I am working on the same thing currently. And the problem I am having is figuring out how to get it where my page displays only the user information that is logged in. I'll locate and post my login.php and main.php on my computer shortly and display the code I currently have and a link to the site so that you can view it.

  6. #6
    Join Date
    Sep 2011
    Posts
    6
    My login.php
    PHP Code:
    <?php
    require("db/conn.php");
    session_start();
    $uname $_POST['uname'];
    $pword $_POST['pword'];
    if(
    $uname&&$pword)
    {
    $query mysql_query("SELECT * FROM users Where uname='$uname'");
    $numrows mysql_num_rows($query);
    if(
    $numrows!=0)
    {
    while (
    $row =mysql_fetch_assoc($query))
    {
    $dbuname $row['uname'];
    $dbpass  $row['pword'];
    }
    if(
    $uname==$dbuname&&md5($pword)==$dbpass)
    {
    echo
    "<script type='text/javascript'>
    <!--
    window.location = 'main.php'
    //-->
    </script>"
    ;
    $_SESSION['uname']=$uname;
    }
    else
        echo 
    "Incorrect Password";

    }
    else
        die(
    "That account doesn't exist.");
    }
    else
        die(
    "Please enter <b>email</b> and <b>password</b>!");

    ?>

  7. #7
    Join Date
    Sep 2011
    Posts
    6
    My main.php file it directs to once the user is loggedin

    PHP Code:
    <?php
    require("db/conn.php"); 
    $sql "select * from users";
    $result mysql_query ($sql);

    while (
    $row mysql_fetch_array($result))
    {
    $field1$row["fname"];
    $field2$row["lname"];
    $field3$row["add1"];
    $field4$row["city"];
    $field5$row["state"];
    $field6$row["zip"];
    $field7$row["country"];
    $field8 $row["mail"];

    echo 
    "
    <table>
            <tr>
                 <td>
                 
    $field1 $field2
                 </td>
            </tr>
            <tr>
                 <td>
                 
    $field3
                 </td>
            </tr>
            <tr>
                <td>
                
    $field4,
                
    $field5
                
    $field6
                </td>
            <tr>
            <tr>
                <td>
                
    $field7
                </td>
            </tr>
            <tr>
                <td>
                
    $field8
                </td>
            </tr>
    </table>
    <br>
    <table>
            <tr>
                 <td>
                 <img src='img/user.png' border='0' width='16px' height='16px'>
                 </td>
                 <td>
                 <font color='#2554C7' face='New Times Roman' size='2'>
                 <a href='details.php' border='0'>Update your details</a>
                 </font>
                 </td>
                 <td>
                 <img src='img/dollar.png' border='0' width='16px' height='16px'>
                 </td>
                 <td>
                 <font color='#2554C7' face='New Times Roman' size='2'>
                 <a href='#' border='0'>Add funds</a>
                 </font>
                 </td>
            </tr>
    </table>
    "
    ;
    }
    ?>

  8. #8
    Join Date
    Sep 2011
    Posts
    6

    New main.php

    I chnaged my main php to this
    PHP Code:
    <?php
    require("db/conn.php"); 
    $id $_SESSION['ID']; //Get user's ID
    $result mysql_query("SELECT * FROM `users` where id='$id'");
    $row mysql_fetch_assoc($result);

    echo 
    "Your user name is: <br>";
    echo 
    $row['fname'];
    echo 
    " and you registered at: <br>";
    echo 
    $row['date'];


    ?>
    Image
    http://www.hellfire-angels.us/examp/example.png

  9. #9
    Join Date
    Sep 2011
    Posts
    6

    Finally coded something that works kind of

    PHP Code:
    <?php
                
    require ("db/conn.php");
                
    session_start();
                
    $user $_SESSION['uname'];
                if(
    $user)
                {
                
    $id $row['id'];
                
    $sql mysql_query"SELECT * FROM users" );
                
    $row mysql_fetch_assoc($sql);
                echo 
    "<tr>
                        <td valign='top'>
                        <font size='2' face='New Times Roman'><strong>First Name:</strong> "
    .$row['fname']."</font><br>
                        <font size='2' face='New Times Roman'><strong>Last Name:</strong> "
    .$row['lname']."</font><br>
                        <font size='2' face='New Times Roman'><strong>Username:</strong> "
    .$row['uname']." </font><br>
                        <font size='2' face='New Times Roman'><strong>E-mail:</strong> "
    .$row['mail']."</font><br>
                        </td>
                       </tr>"
    ;
                }
                else
                    die(
    "");
                
    ?>
    The problem I am having now is that it only displays one user and that's with id of id 1 doesn't show if your id #2 shows ID 1's info not ID 2

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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