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

  • SEARCH
  • Home
  • 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 8032073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:17:05+00:00 2026-06-05T01:17:05+00:00

I am currently working on a website that needs to upload the images of

  • 0

I am currently working on a website that needs to upload the images of different products by its users. I am implementing it by using MySql database via php.

My code for a basic form for taking input from users is:

<form enctype="multipart/form-data" action="testimage1.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>

My database table is:

 mysql> CREATE TABLE tbl_images (
 > id tinyint(3) unsigned NOT NULL auto_increment,
 > image blob NOT NULL,
 > PRIMARY KEY (id)
 > );

testimage1.php has the following code:-

 $username = "root";
 $password = "";
 $host = "localhost";
 $database = "thinstrokes";


 $link = mysql_connect($host, $username, $password);
 if (!$link) {
 die('Could not connect: ' . mysql_error());
 }

// Select your database
mysql_select_db ($database);

    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

  // Temporary file name stored on the server
  $tmpName  = $_FILES['image']['tmp_name'];  

  // Read the file 
  $fp      = fopen($tmpName, 'r');
  $data = fread($fp, filesize($tmpName));
  $data = addslashes($data);
  fclose($fp);


  // Create the query and insert
  // into our database.
  $query = "INSERT INTO tbl_images ";
  $query .= "(image) VALUES ('$data')";
  $results = mysql_query($query, $link) or die(mysql_error());

  // Print results
  print "Thank you, your file has been uploaded.";

  }
  else {
  print "No image selected/uploaded";
  }

On submitting the form I am getting an error: No image selected/uploaded

I am not getting the error… and I’ve already asked for this before as:

  • mysql error during inserting a image in mysql database

  • How can I insert an image in a MySQL database using PHP?

But until now I am not successful in storing the image in the database.

  • 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-06-05T01:17:08+00:00Added an answer on June 5, 2026 at 1:17 am

    Your script is working just fine, This is what I test:

    <?
    
    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 
    
      // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name'];  
    
      // Read the file 
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);
    
    
      // Create the query and insert
    
      // Print results
      print "Thank you, your file has been uploaded.";
    
      }
      else {
      print "No image selected/uploaded";
      }
    
    ?>
    
    <form enctype="multipart/form-data" action="" method="post" name="changer">
    <input name="MAX_FILE_SIZE" value="102400" type="hidden">
    <input name="image" accept="image/jpeg" type="file">
    <input value="Submit" type="submit">
    </form>
    

    And it works just fine, if you want to see it in action I can send you the link.

    It must be something else that is ruining your code (*note that I removed the DB queries to avoid getting mysql errors but the script was working even with them there.

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

Sidebar

Related Questions

I’m currently working on a website that will enable users to upload certain types
I am currently working on a website which needs images to be uploaded. I
I'm currently working on a website that needs a sort of sticky footer, but
I am currently working on a website that users can download binary media files
I'm currently working on a quote retrieval system for my employer's website using mysql/php/html.
I'm currently working on a website that requires me to enable validation for different
I am currently working on a website that will have a high volume of
I am currently working on a website that requires the ability to overwrite the
I'm currently working on a website which is displaying users tweets from the twitter
The project that I'm currently working on involves translating a website that was written

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.