ddarsow Posted June 8, 2009 Share Posted June 8, 2009 I am trying to upload images (and some other data) to a mysql database from a php file. The "other data" associated with the images uploads, but the images themselves do not. The code is as follows: ADD IMAGE FORM: 1. <h1>Upload a New Image</h1> 2. <p>To add a new image, simply fill in the form below and click on the "Upload Image" button located at the bottom of this page. To upload additional images for the property, simply repeat the process for each image.</p> 3. <p> 4. <form class="mid" action="insert_img.php" method="post" onsubmit="this.submit(); this.reset(); return false" enctype="multipart/form-data"> 5. <strong>MLS Number: (REQUIRED!)</strong> <input type="text" name="mls" size="30"><br><br> 6. <strong>IMAGE:</strong> <input name="image" type="file"><br><br> 7. <strong>Thumbnail?:</strong> 8. <SELECT NAME="tn"> 9. <OPTION>N</OPTION> 10. <OPTION>Y</OPTION> 11. </SELECT><br><br> 12. <strong>Alt Text:</strong> <input type="text" name="alt" size="30"><br><br> 13. <strong>Image Title:</strong> <input type="text" name="title" size="60"><br><br> 14. <br><input type="Submit" value="Upload Image"> <input type="reset" value="clear form"> 15. </form> 16. </p> INSERT to DB SCRIPT: 1. <? 2. $username="*****"; 3. $password="*****"; 4. $database="*******"; 5. 6. $mls=$_POST['mls']; 7. $tn=$_POST['tn']; 8. $alt=$_POST['alt']; 9. $title=$_POST['title']; 10. $image=$_POST['image']; 11. 12. $path = $_FILES['image']['tmp_name']; 13. $name = $_FILES['image']['name']; 14. $size = $_FILES['image']['size']; 15. $type = $_FILES['image']['type']; 16. 17. 18. mysql_connect(localhost,$username,$password); 19. @mysql_select_db($database) or die( "Unable to select database"); 20. 21. $query = "INSERT INTO images VALUES ('{}','{$mls}','{$tn}','{$alt}','{$title}','{$name}','{$size}','{$type}','{$image}')"; 22. mysql_query($query); 23. 24. mysql_close(); 25. 26. ?> 27. 28. <script language="javascript"> 29. location.replace("admin.php?page=addimage2"); 30. </script> The field I am trying to insert the images into is a mediumblob Any thoughts? I am new to php, so I suspect it is something simple. Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/161444-php-image-upload-to-mysql-fails/ Share on other sites More sharing options...
fenway Posted June 9, 2009 Share Posted June 9, 2009 Next time, use code blocks, and don't post your access credentials! As for the upload, there are countless tutorials on php image uploads.... Quote Link to comment https://forums.phpfreaks.com/topic/161444-php-image-upload-to-mysql-fails/#findComment-852218 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.