Jump to content

Image Upload to MySql Not Working


Wayniac

Recommended Posts

Greetings everyone,

 

The issue I am having is uploading the image to my database. The config file that is being included is correct and the text uploads perfectly fine when I hit submit. But along with the text, when I hit submit, the image is suppose to upload as well. Unfortunately that is not the case, I check the database field (imgdata) that the image should be stored in and it reads no data, so no image uploaded. There is no image size restriction added yet so that can't be the case. Any suggestions?

 

Here is the code below, thank you very much!

 

<?php
//error_reporting(0);
include("config.php");
// Connect to database

if ($_REQUEST[completed] == 1) {
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['imagefile']['tmp_name'],
"../upload/$newname");
} 

  if(isset($_POST['submit']))

  {

  $newname = mysql_real_escape_string($_POST['imgdata']);

      $title = mysql_real_escape_string($_POST['title']);

      $age = mysql_real_escape_string($_POST['age']);

      $testimonial = mysql_real_escape_string($_POST['testimonial']);

              if(!$title){

                     echo "Error: Entry title is a required field.";

                     exit();

              }

$result = mysql_query("INSERT INTO album (imgdata, title, dtime, age, testimonial)

                       VALUES ('$newname','$title',NOW(),'$age','$testimonial')",$connect);

          echo "<b>Entry UPDATED Successfully!<br>You'll be redirected to View Album page after<br>(4) Seconds";

          echo "<meta http-equiv=Refresh content=4;url=index.php>";

  }

else

  {



      ?>
          </span></h3>
        <h3><span class="TextoBase"><font color=red>
          <?= $errmsg ?>
          </font></span></h3>
        <table border="0">
          <tr>
            <td colspan="4"><form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="" id="form">
                <table width="200" border="0" class="TextoBaseTitulo">
                  <tr>
                    <td> Please choose an image to upload:</td>
                  </tr>
                  <tr>
                    <td><input name="imagefile" type="file" size="28"></td>
                  </tr>
                  <tr>
                    <td>Title:
                      <input type="hidden" name="MAX_FILE_SIZE" value="15000000">
                      <input type="hidden" name="completed" value="1"></td>
                  </tr>
                  <tr class="TextoBase">
                    <td><input name="title" size="40" maxlength="255"></td>
                  </tr>
                  <tr>
                    <td>Age (Years):</td>
                  </tr>
                  <tr class="TextoBase">
                    <td><input name="age" type="text" value="" size="40"></td>
                  </tr>
                  <tr>
                    <td>Testimonial:</td>
                  </tr>
                  <tr class="TextoBase">
                    <td><textarea name="testimonial" rows="7" cols="31"></textarea></td>
                  </tr>
                  <tr>
                    <td><input type="submit" name="submit" value="Add Entry"></td>
                  </tr>
                </table>
              </form></td>
            <td width="120"> </td>
            <td width="233"><img src=?gim=1 alt="" width=250></td>
          </tr>
        </table>
        <?php

  }//end of else

?>
        <span class="TextoBase"> </span></td>
      <td width="137" height="394" class="img_right_panel"> </td>
    </tr>
    <tr>
      <td height="143" colspan="4" align="center" class="img_footer"><p><br>
          <br>
          <a href="http://www.example.com/">Home</a> | <a href="index.php">View Album</a> | <a href="add_entry.php">Add Entry</a>  </p></td>
    </tr>
    <tr>
      <td><img src="images/spacer.gif" width="142" height="1" alt=""></td>
      <td><img src="images/spacer.gif" width="670" height="1" alt=""></td>
      <td><img src="images/spacer.gif" width="1" height="1" alt=""></td>
      <td><img src="images/spacer.gif" width="137" height="1" alt=""></td>
    </tr>
  </table>
</center>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/186762-image-upload-to-mysql-not-working/
Share on other sites

Are you sure that you want to upload image in your database? :confused: Having images in database will slow down your application completely :'(.

 

I wouldn't do that but it depends off your application requirements. Anyway, my advice: do not do that! :o Don't save image in database instead of storing image path only. :shrug:

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.