Note that there are some explanatory texts on larger screens.

plurals
  1. POretrieve and displaying images in php using mysql
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11555084/retrieve-and-insert-image-in-database-using-php">retrieve and insert image in database using php</a> </p> </blockquote> <p>I am inserting and displaying various data with images.I am working on a restyrant website where I am storing and displaying the items along with their images.I have created two tables named food(id[P.K],name,price,image,cat_id[F.K]) category(cat_id[P.K],cat_name) 1-my task is to display the all categories in navigation bar. 2-when I click on the category it should display the food that comes under the category 3-insert and update the information</p> <p>1-My first task was to display the food items onclicking the category.here is the code and it is working perfectly </p> <pre><code> $category=mysql_query("Select * from category",$connection); while($category_name=mysql_fetch_array($category)) { $category_name['cat_name']; echo "&lt;li&gt;&lt;br&gt;&lt;a href=\"show.php?category= ". urlencode($category_name["cat_id"]) . "\"&gt; {$category_name["cat_name"]}&lt;/a&gt;&lt;/li&gt;". "&lt;br /&gt;"; } 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 &lt;form enctype="multipart/form-data" method="post" action="insert.php" &gt; &lt;p&gt;Name:&lt;input type="text" name="food_name" id="food_name"/&gt; &lt;p&gt;Price:&lt;input type="text" name="food_price" id="food_price"/&gt; &lt;input name="MAX_FILE_SIZE" value="102400" type="hidden"&gt; &lt;input name="image" accept="image/jpeg" type="file"&gt; this is the code of of selecting images if (isset($_FILES['image']) &amp;&amp; $_FILES['image']['size'] &gt; 0 &amp;&amp; $_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());} } </code></pre> <p>tell how to insert the images and show them along with other data ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload