Skip to content
Advertisement

Insert image into mysql using php not working

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

Advertisement

Answer

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>
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement