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.