mikesta707 Posted September 10, 2008 Share Posted September 10, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/123539-uploading-script-upload-works-but-insert-into-table-doesnt/ Share on other sites More sharing options...
vicodin Posted September 10, 2008 Share Posted September 10, 2008 Put your errors on E_ALL and see if anything comes up. Quote Link to comment https://forums.phpfreaks.com/topic/123539-uploading-script-upload-works-but-insert-into-table-doesnt/#findComment-638069 Share on other sites More sharing options...
lisa71283 Posted September 10, 2008 Share Posted September 10, 2008 Uncomment the mysql_error() call and let us know what it returns. Are you getting something other than false from the mysql_query() call? Quote Link to comment https://forums.phpfreaks.com/topic/123539-uploading-script-upload-works-but-insert-into-table-doesnt/#findComment-638074 Share on other sites More sharing options...
mikesta707 Posted September 10, 2008 Author Share Posted September 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/123539-uploading-script-upload-works-but-insert-into-table-doesnt/#findComment-638113 Share on other sites More sharing options...
mikesta707 Posted September 10, 2008 Author Share Posted September 10, 2008 anything? is there something wrong with my code? Quote Link to comment https://forums.phpfreaks.com/topic/123539-uploading-script-upload-works-but-insert-into-table-doesnt/#findComment-638519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.