Hi there.
Well i started making a file-uploaded site for the heck of it.
And i decided to add a feature where people can view there own files that they have uploaded.
So i have 2 different tables in my database, 1 for the normal files (For non-logged in people) and 1 for people who are logged in.
Im working on the people who are logged in, and the way i figured out how to do this was to do the $_SESSION code.
I was going to basically, when you upload a file from the membersfiles, it adds 1 more bit of data into a row called username which is not in the upload.php (Which is for everyone).
This would work by me just selecting all the files with the username = $username
But i needed a username to put into my code, and i relised the login scrip uses a $_SESSION.
It has a little bit of code that says "Logged in as" .$_SESSION['user'] (Not exact)"
And considering user is the users username (Duh) i wanted to take this over to the memberfiles upload page so it would use that to put into the row in the DB called username.
I can't really explain it better then that.
Here is my code :
This is for the login.php (The one that i think starts the session)
<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}else{
?>
<form name="login_form" method="post" action="login2.php">
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
<input type="submit" name="login" id="login" value="Login">
</label>
</p>
</form>
<form name="Register" method="post" action="reg.php">
<input type="submit" name="register" id="register" value="Register">
</form>
<?php
}
?>
And here is my Members upload file script
<?php
session_start();
?>
//html stuff :)
<?php
$susername = $_SESSION['user']
$dbhost = "mysql"; //Database Host
$dbuser = "12337_upload"; //Database User
$dbpass = "742634"; //Database Password
$dbname = "12337_upload"; //Database Name
//connect
$db = mysql_pconnect($dbhost,$dbuser,$dbpass);
mysql_select_db("$dbname",$db);
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO userfiles (username, name, size, type, content ) ".
"VALUES ('$susername, $fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
echo "<br><center>File <b>$fileName</b> uploaded</center><br>";
echo "<center><a href='/download.php?id=" . mysql_insert_id() . "'>Click Here to Download</a></center>";
echo "<center>Download Link = http://****.ulmb.com/download.php?id=" . mysql_insert_id() . " </center>";
}
?>
As you can see in the query:
$query = "INSERT INTO userfiles (username, name, size, type, content ) ".
"VALUES ('$susername, $fileName', '$fileSize', '$fileType', '$content')";
$suername is from the $_SESSION['user'];
I wanted just to get the person's username that is logged in, and then store it in the DB alone with the files information, so later i can make a members.php and view all the files if the username from the table = the one in the session?
I know its kinda hard to explain , sorry.
Thanks!
Opps sorry, i forgot the error it was giving me:
Parse error: syntax error, unexpected T_VARIABLE in /hosted/subs/ulmb.com/t/w/***/public_html/membersupload.php on line 49