Hey guys.... please help me out on sorting this php issue... i have made a form to upload images to folder and its details to database but not able to code a form to retrive image from folder and its details from database.


HTML form -

<form method="post" action="addMember.php" enctype="multipart/form-data">
    <p>
            
            </p>
            <p>
              Product Name
            </p>
            <input type="text" name="productname"/>
            
            <br><p>
              Product Image:
            </p>
            <input type="hidden" name="size" value="350000">
            <input type="file" name="photo"> 
        <br>
            <p>
              Product Details :
            </p>
<textarea rows="10" cols="35" name="productdetails">
</textarea>
                     <br/>
            <br/>
            <input TYPE="submit" name="upload" title="Add data to the Database" value="Submit"/>
          </form>

addMember.php -

<?php

//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name=$_POST['productname'];
$pic=($_FILES['photo']['name']);
$about=$_POST['productdetails'];

// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("emp") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO empp (productname,photo,productdetails)
VALUES ('$name', '$pic', '$about')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

I have checked your code its working fine.
What do you mean by code a form to retrieve image.

Well what i exactly mean is using the above form and php file i am able to upload image to folder and its details to the database but m not able to retrive it ..

example :

When i click open view.php


<image1 from folder> - <details of the image1 which is stored in database>

<image2 from folder> - <details of the image2 which is stored in database>

i guess that explains what i actually want...

got it .. the code to view is -

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("emp") or die(mysql_error());
$query = "SELECT * FROM empp";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
Echo "<img src=images/".$row . "><br>";
Echo "<b>Product Name:</b> ".$row . "<br> ";
Echo "<b>Product Details :</b> ".$row . " <hr>"; } ?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.