1

i want to display image from database and below is my code where empid is the value of textbox, it's showing the image name stored in database but i am not able to echo this picture. anyone can help in this regard.

<?php include('connect.php'); $result = $db->prepare("SELECT image FROM info WHERE empid= $empid"); $result->bindParam('$empid', $empid); $result->execute(); for($i=0; $rows = $result->fetch(); $i++){ echo $rows['image']; } ?> 
0

3 Answers 3

1

Change this line.

$result = $db->prepare("SELECT image FROM info WHERE empid= '". $empid ."'"); 
Sign up to request clarification or add additional context in comments.

6 Comments

it is display the name of image.this not display the image
@MuhammadUsman Out a var_dump($row); in the for, and look which item in array is path of image . then use img html tag and put the row['image'] in src attribute.
<img src="images/<?php echo $rows['image']; ?>" width="150" height="150" >
@MuhammadUsman :| Ok <img src="your_image_path/ ".$row['image']." ">
echo "<img src="images/ '.$row["image"].' ">"; this is not working
|
1

its only show you the filename that you stored in your db . if you want to show image then first add folder location with image name and pass into the <img src="excatImageLocation">

Example -

$yourExactPath = "YourImageUploadFolderLocation".$rows['image']; // img/yourFilename.jpg; echo "<img src='$yourExactPath' /> 

8 Comments

i want to search against id
the code i run that is only display the image name..this is not display the image against empid
if its showing right image name then you just need to pass your folder path with image name . DB only store image name but iu also need to store image in a folder.
how can i pass the name of image.while i am searching against different ids
this will give me the same image on every search
|
0

You either concatenate the id onto the text string containing the query or use a parameter place holder and then bind a value to it. Not both, as you were doing.

The most secure way is to use parameters.

<?php include('connect.php'); $result = $db->prepare("SELECT image FROM info WHERE empid= :empid"); $result->bindParam(':empid', $empid, , PDO::PARAM_INT); $result->execute(); while ($row = $result->fetch(PDO::FETCH_ASSOC)){ echo $row['image']; } ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.