Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    5
    Thanked 1 Time in 1 Post

    Username Session Input?

    Alright so the title may be a bit misleading but im working on a social network and i have it at the point where users can Register, log-in, Update Status's, and upload pictures.

    My question is with the upload part of the social network. I have my upload.php that uses connect.php to connect to the database, then after uploading there is a view.php to view the image. My Login files and Upload files were coded separately and now im implementing them together.

    At the top of upload.php i have:

    PHP Code:
    include("connect.php");

    $_SESSION['username']="Anthony Cordio";

    $username $_SESSION['username']; 
    This is where i have the problem, i have a session from before with the log-in that has a username. Instead of manually typing in what username i have to upload as (what other users can do) what would i put to replace "Anthony Cordio" in

    PHP Code:
    $_SESSION['username']="Anthony Cordio"
    So that it pulls a session username from when the user is logged in, In other words i want it to autofill the username from the other session.
    If i didn't do a good job at explaining or you need more explaining let me know.
    Thanks Much, -Anthony

    ALSO:


    connect.php:
    PHP Code:
    <?php

    $error 
    "Unable to connect.";
    $connect mysql_connect("localhost","root","") or die ($error);
    mysql_select_db("phplogin") or die ($error);

    session_start();

    ?>
    login.php:
    PHP Code:
    <?php

    session_start
    ();

    $username $_POST['username'];
    $password $_POST['password'];

    if (
    $username&&$password)
    {

    $connect mysql_connect("localhost","root","") or die("Couldn't connect!");
    mysql_select_db("phplogin") or die ("Couldn't find db");

    $query mysql_query("SELECT * FROM users WHERE username='$username'");

    $numrows mysql_num_rows($query);

    if (
    $numrows!=0)
    {
     
        while (
    $row mysql_fetch_assoc($query))
        {
            
    $dbusername $row['username'];
            
    $dbpassword $row['password'];
        }
        
        
    // check to see if they match
        
    if ($username==$dbusername&&$password==$dbpassword)
        {
            echo 
    "You're in! <a href='member.php'>Click</a> here to continue to the site.";
            
    $_SESSION['username']=$username;
        }
        else
            echo 
    "Incorrect password!";
        
    }
    else
        die(
    "That user doesn't exist!");


    }
    else
        die(
    "Please enter a username and passord");
        
        
    ?>
    Last edited by skill3d; 11-12-2011 at 12:49 AM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,159
    Thanks
    23
    Thanked 599 Times in 598 Posts
    You set $_SESSION['username']; in your login script. You can place that anywhere you want it with php by placing this where the name should be:
    <?php echo $_SESSION['username']; ?>

    But you should do some work on your login script.
    read this:
    http://www.devshed.com/c/a/PHP/Creat...-Login-Script/


  •  

    Posting Permissions

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