Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:40:18+00:00 2026-05-27T20:40:18+00:00

** Solved ** I have a bit of a problem with my code i

  • 0

** Solved **
I have a bit of a problem with my code

i have to store images into a mysql database using php and a HTML form.
I have followed a guide, but i doesnt really work. It uploads the file to the server… and then it gets abandoned… at least not stored.

for the code… the language of text and variables is… Dutch if you have problems with that part ill be glad to help out.

The database layout of the target table is:

Fotos

fotonr        int(10)                       Index number
album         varchar(20)                   Grouping catagory(not needed)
Lid           int(4)                        Index number of the member that placed it
type          varchar(20)                   To store what kind of image it is
image         blob                          The image itself

for that i use the following segment(database links are not in the file, already build before)

<p>
<?php
$target_path= "images/";
echo "checking file upload!<br />";
if(isset($_FILES['file']))
{
    echo"SET!!!<br />";
    if(isset($_POST['album']))
    {
        $album=trim($_POST['album']);
        if($album!="")
        {
            $album=  stripslashes($album);
        }
        else $album="Niet Ingedeeld/";
    }
    else $album="Niet Ingedeeld/";
    $myalbum=mysql_real_escape_string($album);
    $target_path=$target_path.$album;
    foreach($_FILES['file']['tmp_name'] as $key=>$afbeelding)
    {
        echo $_FILES['file']['name'][$key]."<br />";

        if ($_FILES['file']['tmp_name'][$key]!=''){
        $size = getimagesize($_FILES['file']['tmp_name'][$key]);
        $width=$size[0];
        $height=$size[1];
        echo "groote: ".$width."x".$height."<br />";
        if($width>800&&$height>600)
        {
            echo "Uw afbeelding is te groot!(maximaal 800x600)<br />";
        }
        else
        {

            $mynr= mysql_real_escape_string($_SESSION['nummer']);
            /*$type=exif_imagetype($_FILES['file']['tmp_name'][$key]);*/
            $type=$size[mime];
            echo 'Het type was:'.$type.'<br /> ';
            if($type=="image/gif" ||$type=="image/jpeg" ||$type=="image/bmp" ||$type=="image/png" ||$type=="image/gif" ){
            $mytype =mysql_real_escape_string($type);
            $tmpName  = $_FILES['file']['tmp_name'][$key];

            /*$fp      = fopen($tmpName, 'r');
            $content = fread($fp, filesize($tmpName));
            $mycontent = mysql_real_escape_string($content);*/
            $content = file_get_contents($tmpName); 
            $data = unpack("H*hex", $content ); 
            $mycontent = '0x'.$data['hex']; 


            $sql="INSERT INTO`nacverk`.`Foto` (`album` , `lid` ,`image`,`type` )VALUES ('$myalbum' ,'$mynr','$mycontent', '$mytype')";

            $result=mysql_query($sql); 
            /*fclose($fp);*/
            if(!$result)
            {
                echo "<h1>Bestand uploaden mislukt!<br /> ".mysql_error()."<br /></h1>";
            }
            else
            {
                echo "<h1>Bestand Succesvol geupload!<br /></h1>";
            }
            }
            else{
                echo "<h1> NOD32 detected a viral intrusion!<br /></h1>";
            }

        }

    }}
}
mysql_query("OPTIMIZETABLE `Foto` ");
?>
</p><hr />
<h3> Upload hier uw Foto's!</h3>
<hr />
<p>
<form enctype="multipart/form-data" action="" method="post" name="foto-upload">
<input name="MAX_FILE_SIZE" value="10485760" type="hidden">
Uw afbeeldingen:<br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
<input name="file[]"  type="file"><br />
Het album waar ze aan toegevoegd moeten worden:<br />
<input name="album" type="text" maxlength="20"
<?php if(isset($_GET['album']))echo ' value="'.$_GET['album'].'" '; ?>><br />
<input value="Submit" type="submit">
</form>
</p>
<hr />

It falls through till the part where it needs to get uploaded to the Database…
Then it triggers the SQL error saying: Query is empty.

Thank you for you time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:40:18+00:00Added an answer on May 27, 2026 at 8:40 pm

    Keep in mind the maximum length for a BLOB data type is 64KB. It’s pretty common for images to be larger, so perhaps you should use MEDIUMBLOB.

    See http://dev.mysql.com/doc/refman/5.1/en/string-type-overview.html for more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webapp written in PHP using a MySQL database backend. This question
NOTE: I have solved the majority of this problem but have run into a
I solved a problem recently. But I have this one piece of code where
Learning php! I have a sql database which contains a table called 'images' which
I have solved this problem, I just need to know what to do. I
I have a problem that I would like have solved via a SQL query.
I'm curious how others have solved this problem, and what problems might lurk behind
The responses I've got to this question have solved the problem I had in
I'm sure this is the kind of problem other have solved many times before.
In my WPF application I have some drawing functionality. I have solved this using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.