Jump to content

Uploading script. Upload works, but insert into table doesn't


mikesta707

Recommended Posts

Hey, i'm fairly new to PHP ( i have experience with pretty simple databasing stuff) but i recently got my own web server, and on this server I created an upload script. What it does is pretty simple, uploads whatever file into a directory named after the user (ie my directory would be uploads/mikesta707) and this works like a charm

 

however, I also have the script insert some information about the upload into the table (the file size, file type, uploader, etc.) and when i first ran this script, it worked like a charm. Well, after making a few changes (those changes simply being adding a few more variables to insert into the table) the insert stopped working! I really have no clue why. The page isn't giving me any error messages, and its even going so far as to say it is inserting the stuff into the table.

 

well heres my code:

<?
if (!isset($_SESSION['Username']))
{
echo "You can not upload files without logging in, thank you. if you wish to login, go to the <a href='index.php'>main</a> page.";
exit();
}
//mkdir

$uname = strtolower($_SESSION['Username']);
if (!file_exists('Uploads/' . $uname)) {
mkdir('Uploads/'. $uname);
}

#These are just the variables that i need for the script
$target_path = "Uploads/". $uname . "/";
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$file_aff = $_POST['aff'];
$file_type1 = $_POST['type1'];
$file_name = $_POST['filename'];
$desc = $_POST['desc'];


$target_path = $target_path . basename( $_FILES['file']['name']); 
$_FILES['file']['tmp_name'];  

if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) 
{
$insert2 = "INSERT INTO upload SET uploader='$uname', name='$file_name', type='$file_type1', ftype='$file_type', size='$file_size', 	aff='$file_aff', path='$target_path', desc='$desc'";
mysql_query($insert2);
if ($insert2) 
{
	echo "Table information entered<br>";
	//$err = mysql_error();
	//print $err;
	//exit();
#originally this part went if (!insert, and showed the error, but i commented that out to see if it was just not doing this step and no #saying anything
} 

    echo "The file ".  basename( $_FILES['file']['name']). 
    " has been uploaded<br>";
echo "The file has been saved as " . $file_name . "<br> uploaded by " . $uname . "<br>";
if (isset($file_aff)){
echo "The creater of this is " . $file_aff . "<br> thank you for submitting this";
}




} 

else{
    echo "There was an error uploading the file, please try again!";
echo $_FILES['file']['error'];

}

?>

 

What is really confusing me is that im not even getting any errors. When i go to my phpmyadmin page, and see if there are any entries on the table, it just comes out empty. I am seriously lost. Can anyone help?

Link to comment
Share on other sites

See, i've had the mysql_error uncommented for a while, I just recently commented it out. The thing thats so confusing is that I am getting no errors. Like absolutely fine. I know its not a problem with the upload itself (if there was it wouldn't run the rest of the script, and it wouldnt go to the table) because the stuff appears at the correct place on the server

 

Its really strange, I was looking for what the error was, and it just doesn't come up with one. Hell, i have run what it currently is now, and the mysql_query is returning true because it says that echo statement i have in the if statement.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.