0

I have website that insert some info's like name , date , msg and IMG into mysqli database here is my CODE

HTML & PHP CODE

<form action='' method='POST'>
                <input type='date' name='bdate' min='2003-12-31' max='2016-04-02'><br><br> 
                  <input type='text' name='send_name'/>
                  <input type='text' name='min_name'  value='Some Name' disabled='true' ><br>   
                <textarea name='my_text' rows='11' cols='40'></textarea>
                      <input type='submit' name='submit' value='Send'>
                      <input type='file' name='Image' id='Image' >
                </form>

if (isset($_POST['submit'])) {
              $imgData = $_FILES['Image']['tmp_name'];
              $imageProperties = $_FILES['Image']['tmp_name'];
              $sql = "INSERT INTO output_images(imageType ,imageData)
              VALUES('".$imageProperties['mime']."', '".$imgData."')";
              $current_id = mysqli_query($connection,$sql) or die("<b>Error:</b> Problem on Image Insert<br/>" . mysqli_error());
              if(isset($current_id)) {
                echo "Image Upload Ok";
                }
                $imgData = $_FILES['Image']['tmp_name'];
                $imageProperties = $_FILES['Image']['tmp_name'];
                $min_name = "Ministry Of Intinor";
                $dat = $_POST['bdate'];
                $info = $_POST['my_text'];
           $mySQL = mysqli_query($connection," INSERT INTO `mddb`.`ministry_tbl` (`sender_name`, `min_name`, `b_date`, `infos`,`img`,`img_name`) VALUES ('".$_SESSION['username']."', '".$min_name."', '".$dat."', '".$info."','".$imgData."','".$imageProperties['mime']."') ");
              if ($mySQL) {
                echo "Done";
              }
            }
          

My problem is the database not store the BLOB* img and its always [BLOB - 0 B]

NOTE enter image description here

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Amosh Amosh
  • 37
  • 1
  • 1
  • 4

2 Answers2

0
you have to use enctype="multipart/form-data" add input type="file" before submit button

            <input type='date' name='bdate' min='2003-12-31' max='2016-04-02'><br><br>

              <input type='text' name='send_name'/>
              <input type='text' name='min_name'  value='Some Name' disabled='true' ><br>   
            <textarea name='my_text' rows='11' cols='40'>
                <input type='file' name='Image' id='Image' >
                  <input type='submit' name='submit' value='Send'>


            </form>
Arun Kumaresh
  • 6,211
  • 6
  • 32
  • 50
0

A better approach is to not save images in database as it is not a good practice. Just save the uploaded image in a directory and save the path to that image in database. It would save you some database space and search time.

For reference please view my answer here PHP-SQL: Uploaded image displaying as junk text

Community
  • 1
  • 1
Noor Ahmed
  • 1,507
  • 9
  • 14