display username after logging in
Results 1 to 3 of 3

Thread: display username after logging in

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    19

    display username after logging in

    Hi

    I really need some help with PHP

    I am trying code something like the following

    After a user logs in, I want a page to display his username, how do I do that

    On the page where I want to display the username, I have got the following PHP coding so far

    PHP Code:
    <?php
    //set vars
    $user $_POST['user'];
    $pass md5($_POST['pass']);

    if (
    $user&&$pass
    {
    //connect to db
    $connect mysql_connect("$hostname","$username","$password") or die("not connecting");
    mysql_select_db("databasename") or die("no db :'(");
    $query mysql_query("SELECT * FROM $tablename WHERE username='$user'");
    ?>
    My login php page coding is below

    PHP Code:
    <?php
    //set vars
    $user $_POST['user'];
    $pass md5($_POST['pass']);

    if (
    $user&&$pass
    {
    //connect to db
    $connect mysql_connect("$hostname","$username","$password") or die("not connecting");
    mysql_select_db("databasename") or die("no db :'(");
    $query mysql_query("SELECT * FROM $tablename WHERE username='$user'");

    $numrows mysql_num_rows($query);


    if (
    $numrows!=0)
    {
    //while loop
      
    while ($row mysql_fetch_assoc($query))
      {
        
    $dbusername $row['username'];
        
    $dbpassword $row['password'];
      }
      else
          die(
    "incorrect username/password!");
    }
    else
      echo 
    "user does not exist!";

    else
        die(
    "please enter a username and password!");
    ?>
    <br>
    <div id="login">
    Enter username and password below to login
    </div>
    <form id='login' action='checklogin.php' method='post' accept-charset='UTF-8'>
    <fieldset>
    <legend></legend>
    <input type='hidden' name='submitted' id='submitted' value='1'/>
    <label for='username' >Username*:</label>
    <input type='text' name='username' id='username'  maxlength="50" />
    <label for='password' >Password*:</label>
    <input type='password' name='password' id='password' maxlength="50" />
    <input type='submit' name='Submit' value='Login' />
    </fieldset>
    </form>
    <br><br>
    <div id="forgot">
    Enter your registered email address below to generate a new password
    </div>
    <form method="post" action="forgotpassword.php">
    <label for="email">Email:</label>
    <input type="text" title="Please enter your email address" name="email" size="30"/>
    <input type="submit" value="Submit" class="submit-button"/>
    </form>
    My registration form coding is below

    PHP Code:
    <?php
    //=============Configuring Server and Database=======
    $host        =    'hostname';
    $user        =    'username';
    $password    =    'password';
    //=============Data Base Information=================
    $database    =    'databasename';
     
    $conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
    mysql_select_db($database,$conn) or die('Database Information is not correct');
     
    //===============End Server Configuration============
     
    //=============Starting Registration Script==========
     
    $email    =    $_POST['email'];

    $username    =    $_POST['txtUser'];
     
    $password    =    $_POST['txtPassword'];
     
    //=============To Encrypt Password===================
    $password    =    md5($salt.$password);
    //============New Variable of Password is Now with an Encrypted Value========
     
    if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register
    {
    $query    =    "insert into users(email,username,password)values('$email','$username','$password')";
    $res    =    mysql_query($query);
    header('location:registersuccess.html');
    }
     
    ?>

    <?php
    $to 
    "$email";
    $subject "Registration Details";
    $message "Email: $email \n Username: $username \n Password: $password";
    $from "myemailaddress";
    $headers "From: $from";
    mail($to,$subject,$message,$headers);
    echo 
    "Mail Sent.";
    ?>

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,774
    What's wrong with
    PHP Code:
    echo $user
    ?
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Location
    Iowa, USA
    Posts
    132
    I think the best way that you could go about doing this would be via sessions. Read up on them and if you have any questions feel free to post back and we'll do what we can to get you up and running.

    A quick Google search gave me some tutorials that might help you understand them.
    http://www.tizag.com/phpT/phpsessions.php
    http://www.htmlgoodies.com/beyond/ph...l-Sessions.htm
    and lastly from the PHP manual: http://us2.php.net/manual/en/book.session.php

    Hope this helps you out

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
  •