rog1121 Posted May 19, 2011 Share Posted May 19, 2011 I've Basically got this script and everything works. Except for the part that it doesen't insert "$_FILES['file']['name']" into the image_url. Any Ideas guys? <? include "includes/config.php"; if (isset($_POST['add'])) { if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("images/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; echo $_FILES['file']['name']; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $_FILES["file"]["name"]); } } } else { echo "Sorry, but only PNG, JPG, and GIF files are allowed."; } mysql_connect ($mysql_host, $mysql_user, $mysql_pass); mysql_select_db ($mysql_db); $image_url = "http://localhost/admin/images/". $_FILES['file']['name'] .""; $sql = "INSERT INTO test (title, link, description, image_url) VALUES ('$_POST[title]', '$_POST[link]', '$_POST[description]', '$image_url')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header( 'Location: portfolio.php' ); mysql_close(); } ?> <form enctype="multipart/form-data" method="post"> <p> <strong>TITLE</strong><br/> <input type="text" name="title" class="box"/> </p> <p> <strong>LINK</strong><br/> <input type="text" name="link" class="box"/> </p> <p> <strong>IMAGE</strong><br/> <input type="file" class="box" name="file"/> </p> <p> <strong>DESCRIPTION</strong><br/> <input type="textarea" name="description" class="box"/> </p> <p> <input name="add" type="submit" id="submit" tabindex="5" class="com_btn" value="ADD WORK"/> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/236915-wont-insert-file-name-into-sql/ Share on other sites More sharing options...
Rifts Posted May 19, 2011 Share Posted May 19, 2011 what happens when you echo $image_url also why is there extra space at the end of this $image_url = "http://localhost/admin/images/". $_FILES['file']['name'] .""; make it $image_url = "http://localhost/admin/images/". $_FILES['file']['name']; Quote Link to comment https://forums.phpfreaks.com/topic/236915-wont-insert-file-name-into-sql/#findComment-1217847 Share on other sites More sharing options...
rog1121 Posted May 19, 2011 Author Share Posted May 19, 2011 what happens when you echo $image_url also why is there extra space at the end of this $image_url = "http://localhost/admin/images/". $_FILES['file']['name'] .""; make it $image_url = "http://localhost/admin/images/". $_FILES['file']['name']; This is what happens But its still not entering the full url in the DB Quote Link to comment https://forums.phpfreaks.com/topic/236915-wont-insert-file-name-into-sql/#findComment-1217851 Share on other sites More sharing options...
rog1121 Posted May 19, 2011 Author Share Posted May 19, 2011 Edit: it seems that I set the limit of the Text length to 30 in the DB lol. Stupid me.... Sorry for the trouble Quote Link to comment https://forums.phpfreaks.com/topic/236915-wont-insert-file-name-into-sql/#findComment-1217856 Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 At the top of the script, put the following code and post the output it generates after the form has been submitted. echo '$_FILES array contains:<br>'; echo '<pre>'; print_r($_FILES); echo '</pre>'; EDIT: Nevermind, you must have been marking it solved as I was posting . . . Quote Link to comment https://forums.phpfreaks.com/topic/236915-wont-insert-file-name-into-sql/#findComment-1217857 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.