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 8551511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:12:42+00:00 2026-06-11T14:12:42+00:00

i have upload the images in databases but when i want to display it

  • 0

i have upload the images in databases but when i want to display it the images cannot display..i don’t know why it cannot display..maybe have something wrong in my coding..can you please help me??

upload.php

<?php

$id = $_POST['account'];
$code = $_POST['code'];
$price = $_POST['price'];

echo $file = $_FILES['image']['tmp_name'];
if (!isset($file))
  echo "Please select an image.";
else
{
 $image = addslashes (file_get_contents($_FILES['image']['tmp_name']));
 $image_name = addslashes ($_FILES['image']['name']);
 $image_size = getimagesize($_FILES['image']['tmp_name']);

 if($image_size==FALSE)
  echo "That's not an image.";
else
{
if (!$insert = mysql_query("INSERT INTO menu 
    VALUES('$code','$price','$image','$id')"))
echo "Problem uploading images.";
else
{
  $lastid = $code;
  echo "Image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
}

   }
 }
 ?>

get.php

 <?php
 $con = mysql_connect("localhost","root","");
 if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

 mysql_select_db("food", $con);


 $id = addslashes($_REQUEST['FoodId']);

 $image = mysql_query("SELECT * FROM menu WHERE FoodId=$id");
 $image = mysql_fetch_assoc($image);
 $image = $image['image'];

 header("Content-type: image/jpeg");

 echo $image;
 ?>
  • 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-11T14:12:43+00:00Added an answer on June 11, 2026 at 2:12 pm

    Please confirm by manually looking through your DB that the image has been stored successfully, and infact is readable?, post the contents of the stored image.

    FYI, it is usually better to store the image in a folder on your server, rather than in the DB and just store the path to the image in the DB.

    If you wanted to store path to image, something like this would work:

    <?php
    
    $id = mysql_real_escape_string($_POST['account']);
    $code = mysql_real_escape_string($_POST['code']);
    $price = mysql_real_escape_string($_POST['price']);
    
    $allowedExts = array("jpg", "jpeg", "gif", "png");
    if(!isset($_FILES))
    {
        die('No Image Uploaded - Please check form enctype="multipart/form-data".');
    }
    $fileinfo = pathinfo($_FILES['image']['name']);
    $extension = $fileinfo['extension'];
    if(!in_array($extension,$allowedExts))
    {
        die('Invalid file type.');
    }
    $file   = '/uploadedimages/' . uniqid() .'.'. $extension;
    if(!move_uploaded_file($_FILES['image']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . $file))
    {
        die('Problem Storing Image in folder /uploadedimages/ - Please check folder exists and is writable.');
    }
    
    $insert = mysql_query("INSERT INTO menu VALUES('$code','$price','$file','$id')");
    if(!$insert)
    {
        die('Problem adding to db.');
    }
    /*
    the following two echos demostrate two methods of showing the image, 
    the first adds the variable by splitting the string and rejoining it,
    the second nests the image inside the variable without the need to edit it.
    
    The difference is the single and double quotes, single quotes take any content 
    inside them as litteral, meaning 
        $string = "hello";
        $new_string = '$string Dave.';
        will print $string Dave. Not hello Dave.
    Double quotes will accept variables and add the content they hold.
        $string = "hello";
        $new_string = "$string Dave.";
        will print hello Dave.
    */
    echo 'Image Uploaded.<p>Your Image</p><img src="' . $file . '" />';
    
    echo "Image Uploaded.<p>Your Image</p><img src=\"$file\" />";
    

    the folder is /uploadedimages/ and would need to be write enabled (chmod777)

    Calling from another file;
    You can call the image anytime from the DB with the query you used before;

    $res = mysql_query("SELECT * FROM menu WHERE FoodId=$id");
    $row = mysql_fetch_assoc($res);
    $image = $row['image'];
    ?>
    <img src="<?=$image?>" />
    

    Obviously the $id is something you have already defined on the php page.

    EDIT: The edit made by someone else to me post was unnecessary – there is nothing wrong with using single quotes with variables and it clearly shows where you are adding variables in. If you wanted to show how to use double quotes you should give both options available and explain the difference. Your edit was tacky and badly written, adding a space after the double quote.

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

Sidebar

Related Questions

We have a CMS where people can upload images. We currently don't offer a
I have users that have several objects and can upload images for those objects.
I have a file upload script that works [finally] but want to have users
I want to upload images and they must be store in media folder.But when
I have a form to upload images to my website. The consists on a
I have created a program which allows me to upload images to my server.
I have a web application in which a user has to upload images to
Let say, I have a web application that allows users to upload images and
I have use these code to upload two images in folder of the root
I have a desktop application that needs to upload/download images to/from service computer over

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.