可能重复在PHP中显示图像:
retrieve and insert image in database using php检索和用mysql
我将和显示各种数据与images.I我在restyrant网站工作的我在哪里存储并显示项目及其图像。我创建了两个名为food(id [PK],name,price,image,cat_id [FK])类别(cat_id [PK],cat_name)的表格1-我的任务是显示导航栏中的所有类别。 2 - 当我点击类别时,应该显示属于类别3的食物并插入信息并更新信息
1-我的第一项任务是显示点击类别的食物项目。有代码和它正在完美运作
$category=mysql_query("Select * from category",$connection);
while($category_name=mysql_fetch_array($category))
{
$category_name['cat_name'];
echo "<li><br><a href=\"show.php?category=
". urlencode($category_name["cat_id"]) . "\">
{$category_name["cat_name"]}</a></li>". "<br />";
}
if(isset($_GET['category']))
{
$query="Select * from food where cat_id={$_GET['category']} ";
$result=mysql_query($query,$connection);
while($food_name=mysql_fetch_array($result))
{
echo $food_name["food_name"]. " Price is " . $food_name["food_price"];
here i have to use the code inorder to display the images
}
here is code of inserting the data and images
this is the html form inserting fields in the database
<form enctype="multipart/form-data" method="post" action="insert.php" >
<p>Name:<input type="text" name="food_name" id="food_name"/>
<p>Price:<input type="text" name="food_price" id="food_price"/>
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
this is the code of of selecting images
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0 && $_POST['cat_name'])
{
// 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);
$cat_id=$_POST['cat_name'];
$food_name=$_POST['food_name']
$foodPrice=$_POST['food_price'];
$query="INSERT INTO food (cat_id, food_name, food_price,image) VALUES
($cat_id,'$food_name','$foodPrice','$data')";
if(mysql_query($query,$con))
{
echo "New Item Added in the DataBase and picture has been uploaded";
}
else
{ die(mysql_error());}
}
说明如何插入图像并将它们与其他数据一起显示?
第三次,你都张贴了这个问题。 – 2012-07-19 06:56:07