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

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

its worksssss ^_^ thanx for help , but with One Error says Warning: Illegal string offset 'mime' in C:\wamp\www\members_area\html\ministry.php on line 158
what is in the line number 158?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.