chris_rulez001 Posted June 29, 2007 Share Posted June 29, 2007 hi ive made a script to make my users upload files and its not working, i am getting no error but just nothing what so ever the script: <?php session_start(); $id = $_POST['id']; $username = $_SESSION['username']; if ($_FILES["file"]["type"] == "image/gif") || $_FILES["file"]["type"] == "image/pjpeg") || $_FILES["file"]["type"] == "image/png") || $_FILES["file"]["type"] == "image/bmp") || $_FILES["file"]["type"] == "movie/swf") || $_FILES["file"]["type"] == "image/jpeg") || $_FILES["file"]["type"] == "music/mp3") || $_FILES["file"]["type"] == "music/wma") && ($_FILES["file"]["size"] < 5000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("memberuploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { $filename = $_FILES["file"]["name"]; move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "memberuploads/" . $_FILES["file"]["name"]; $dbh=mysql_connect("fdb1.awardspace.com", "cgitesting221_ss", "buzzer2242") or die ('Connection to database failed: ' . mysql_error()); mysql_select_db("cgitesting221_ss"); $today = date("D M d Y"); $filetype = $_FILES["file"]["type"]; $file size = $_FILES["file"]["size"]; mysql_query("INSERT INTO tracking (id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today, '$_SERVER['REMOTE_ADDR']', '$filename', '$filetype', $filesize')") or die(mysql_error()); } } } else { echo "Invalid file"; } ?> can someone help me? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 29, 2007 Author Share Posted June 29, 2007 hi ive made a script to make my users upload files and its not working, i am getting no error but just nothing what so ever the script: <?php session_start(); $id = $_POST['id']; $username = $_SESSION['username']; if ($_FILES["file"]["type"] == "image/gif") || $_FILES["file"]["type"] == "image/pjpeg") || $_FILES["file"]["type"] == "image/png") || $_FILES["file"]["type"] == "image/bmp") || $_FILES["file"]["type"] == "movie/swf") || $_FILES["file"]["type"] == "image/jpeg") || $_FILES["file"]["type"] == "music/mp3") || $_FILES["file"]["type"] == "music/wma") && ($_FILES["file"]["size"] < 5000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("memberuploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { $filename = $_FILES["file"]["name"]; move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "memberuploads/" . $_FILES["file"]["name"]; $dbh=mysql_connect("fdb1.awardspace.com", "", "") or die ('Connection to database failed: ' . mysql_error()); mysql_select_db("cgitesting221_ss"); $today = date("D M d Y"); $filetype = $_FILES["file"]["type"]; $file size = $_FILES["file"]["size"]; mysql_query("INSERT INTO tracking (id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today, '$_SERVER['REMOTE_ADDR']', '$filename', '$filetype', $filesize')") or die(mysql_error()); } } } else { echo "Invalid file"; } ?> can someone help me? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 29, 2007 Author Share Posted June 29, 2007 bump, i need some help please Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 29, 2007 Author Share Posted June 29, 2007 bump, help, someone? Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 30, 2007 Share Posted June 30, 2007 Well, I am not sure whats wrong, but I did see this: $id = $_POST['id']; $username = $_SESSION['username']; if ($_FILES["file"]["type"] == "image/gif") || $_FILES["file"]["type"] == "image/pjpeg") || $_FILES["file"]["type"] == "image/png") || $_FILES["file"]["type"] == "image/bmp") || $_FILES["file"]["type"] == "movie/swf") || $_FILES["file"]["type"] == "image/jpeg") || $_FILES["file"]["type"] == "music/mp3") || $_FILES["file"]["type"] == "music/wma") && ($_FILES["file"]["size"] < 5000)) you could try to change that to: $id = $_POST['id']; $username = $_SESSION['username']; if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "movie/swf") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "music/mp3") || ($_FILES["file"]["type"] == "music/wma") && ($_FILES["file"]["size"] < 5000)) Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 1, 2007 Author Share Posted July 1, 2007 thanks, im getting an error, Parse error: syntax error, unexpected T_BOOLEAN_OR in /home/www/hostsareus.awardspace.co.uk/file_upload2.php on line 4 code: <?php $id = $_POST['id']; $username = $_SESSION['username']; if (($_FILES["file"]["type"] == "image/gif") || $_FILES["file"]["type"] == "image/pjpeg") || $_FILES["file"]["type"] == "image/png") || $_FILES["file"]["type"] == "image/bmp") || $_FILES["file"]["type"] == "movie/swf") || $_FILES["file"]["type"] == "image/jpeg") || $_FILES["file"]["type"] == "music/mp3") || $_FILES["file"]["type"] == "music/wma") && ($_FILES["file"]["size"] < 5000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("memberuploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "memberuploads/" . $_FILES["file"]["name"]; $filename = $_FILES["file"]["name"]; $dbh=mysql_connect("fdb1.awardspace.com", "myusername", "mypassword") or die ('Connection to database failed: ' . mysql_error()); mysql_select_db("mydatabase"); $today = date("D M d Y"); $filetype = $_FILES["file"]["type"]; $file size = $_FILES["file"]["size"]; mysql_query("INSERT INTO tracking (id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today, '$REMOTE_ADDR', '$filename', '$filetype', $filesize')") or die(mysql_error()); } } } else { echo "Invalid file"; } ?> Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 bump Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 bump need help please Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 What was the first error you got on your code? Was it the same: Parse error: syntax error, unexpected T_BOOLEAN_OR in /home/www/hostsareus.awardspace.co.uk/file_upload2.php on line 4 Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 there was no first error on my code, the boolean problem happened after i added an extra ( on line 4 Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 I can't seem to find any thing wrong.. The only thing I can possibly think if is removing the ")"s like below <?php if( $_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/bmp" || $_FILES["file"]["type"] == "movie/swf" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "music/mp3" || $_FILES["file"]["type"] == "music/wma" && $_FILES["file"]["size"] < 5000 ) ?> I guess try this, but I really have no idea other wise.. Kinda odd Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 ok the boolean error has gone but another error has occured: Parse error: syntax error, unexpected T_STRING in /home/www/hostsareus.awardspace.co.uk/file_upload2.php on line 44 code: <?php $id = $_POST['id']; $username = $_SESSION['username']; if( $_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/bmp" || $_FILES["file"]["type"] == "movie/swf" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "music/mp3" || $_FILES["file"]["type"] == "music/wma" && $_FILES["file"]["size"] < 5000 ) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("memberuploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "memberuploads/" . $_FILES["file"]["name"]; $filename = $_FILES["file"]["name"]; mysql_connect("fdb1.awardspace.com", "myusername", "mypassword") or die ('Connection to database failed: ' . mysql_error()); mysql_select_db("mydatabase"); $today = date("D M d Y"); $filetype = $_FILES["file"]["type"]; $file size = $_FILES["file"]["size"]; mysql_query("INSERT INTO tracking (id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today, '$REMOTE_ADDR', '$filename', '$filetype', $filesize')") or die(mysql_error()); } } } else { echo "Invalid file"; } ?> Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 OK found it. You have <?php $file size = $_FILES["file"]["size"]; ?> you left a space between file and size just change it to $filesize. I've also found a potential error on line 46 near the end of your query: '$filetype', $filesize')") or die(mysql_error()); -- you're missing a ' right before $filesize' Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 thanks, after i click sumbit on my form it shows info i want but its showing other errors: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near " at line 1 code: <?php $id = $_POST['id']; $username = $_SESSION['username']; if( $_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/bmp" || $_FILES["file"]["type"] == "movie/swf" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "music/mp3" || $_FILES["file"]["type"] == "music/wma" && $_FILES["file"]["size"] < 5000 ) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("memberuploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "memberuploads/" . $_FILES["file"]["name"]; $filename = $_FILES["file"]["name"]; mysql_connect("fdb1.awardspace.com", "*****", "*****") or die ('Connection to database failed: ' . mysql_error()); mysql_select_db("*******"); $today = date("D M d Y"); $filetype = $_FILES["file"]["type"]; $filesize = $_FILES["file"]["size"]; mysql_query("INSERT INTO tracking (id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today, '$REMOTE_ADDR', '$filename', '$filetype', '$filesize')") or die(mysql_error()); } } } else { echo "Invalid file"; } ?> Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 Ahh there we are. 99% of the time is something simple, usually in open but hard to find. I should of caught this while looking at your query the first time: You have VALUES ('$id', '$username', '$today, '$REMOTE_ADDR' '$today is missing a ' should be VALUES ('$id', '$username', '$today', '$REMOTE_ADDR' Let's see if this works. Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 right ive added it and it is still showing: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 Stubborn query! You mentioned that you saw the information you wanted. I'm assuming that would be the file, file size etc? Could you post that. I'm wondering if there is may be a ' or \ in there something to interrupt the query. I really looks fine. Do you know what version of MySQL and php you're running? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 yeah you're right it is stubbon, i dont know what version of php and mysql, ive just tried something and its worked, ive changed: mysql_query("INSERT INTO tracking(id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today', '$ip', '$filename', '$filetype', '$filesize'") or die(mysql_error()); to mysql_query("INSERT INTO tracking(id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today', '$ip', '$filename', '$filetype', '$filesize')"); Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 i have another problem, no errors are showing, its not importing the username into the database heres my code: <?php $id = $_POST['id']; $username = $_POST['username']; if( $_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/bmp" || $_FILES["file"]["type"] == "movie/swf" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "music/mp3" || $_FILES["file"]["type"] == "music/wma" && $_FILES["file"]["size"] < 5000 ) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "<h4>Upload Successful!</h4><br/>"; echo "<strong>Upload:</strong> " . $_FILES["file"]["name"] . "<br /><br />"; echo "<strong>Type:</strong> " . $_FILES["file"]["type"] . "<br /><br />"; echo "<strong>Size:</strong> " . ($_FILES["file"]["size"] / 1024) . " Kb<br /><br />"; echo "<strong>Temp file:</strong> " . $_FILES["file"]["tmp_name"] . "<br /><br />"; if (file_exists("memberuploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "memberuploads/" . $_FILES["file"]["name"]); echo "<strong>Stored in:</strong> " . "http://*****************/memberuploads/" . $_FILES["file"]["name"]; echo "<br/><br/><strong>ALL</strong> inappropriate images, movies, music <strong>WILL</strong> be deleted!"; $filename = $_FILES["file"]["name"]; mysql_connect("fdb1.awardspace.com", "**********", "********") or die ('Connection to database failed: ' . mysql_error()); mysql_select_db("*********"); $today = date("D M d Y"); $filetype = $_FILES["file"]["type"]; $filesize = $_FILES["file"]["size"]; $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO tracking(id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today', '$ip', '$filename', '$filetype', '$filesize')"); } } } else { echo "Invalid file"; } ?> Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 Hmm odd when I was looking at the code you had included that last bit: ')"); The $username = $_POST['username']; Is there a text field that the user has to enter their name? If there is make sure the <input name="" field is correct. Check the spelling. Probably 90% of the time when this happens to me It because I misspell a filed something like uesrname instead of username. If you don't have a text field that the user fills out, did you mean $_SESSION['username']? Would you mind posting the <form></form> code? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 <form action='file_upload2.php' method='post' enctype='multipart/form-data'> <br/><input type='file' name='file' id='file' size='50'/><br/><br/><strong>File Extensions Allowed:</strong> MP3, WMA, JPEG, PNG, GIF, BMP, SWF<br/><strong>File Size Limit:</strong> 5000 KB<br/> <br /> <input name='username' type='hidden' value='".$_SESSION['username']."'/> <input type='submit' name='submit' value='Submit' /> <input type='reset' name='Reset' value='Reset' /> </form> theres the form Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 I see the hidden field, username. You do have the value set to $_SESSION['username']. You may just want to eliminate this hidden field. Manly for 2 reason. One is redundancy and second, security. Normally a user cannot modify a session; however, since you've added a hidden field, you actually unintentionally giving the use a chance to change their username with this. So in your php where you have $username = $_POST['username']; you may just want to say $username = $_SESSION['username']; Now for the insert error. You may want to do a quick check to see if there is a value in $_SESSION['username'] You can also view the source of the page and see if that hidden field has a value. Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 ok its worked now with the $_SESSION['username'], thanks for all your help Quote Link to comment Share on other sites More sharing options...
Salis Posted July 2, 2007 Share Posted July 2, 2007 No problem. Good to hear it works now. Quote Link to comment 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.