View Full Version : Username Session Input?

11-12-2011, 01:47 AM
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:


$_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

$_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




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






$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.";
echo "Incorrect password!";

die("That user doesn't exist!");

die("Please enter a username and passord");


11-12-2011, 09:25 AM
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:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum