Jump to content

php image upload to mysql fails


ddarsow

Recommended Posts

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

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.