Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
this my code but unable to display image from db in php.i think this is not pick up the path.any one 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 '<img src="images/".$row["image"]." ">';
echo '<img src="images/".$row["image"]. > ' ;
}
?>
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');
// I assume you have set $empid somewhere in the missing code here
$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)){
// also changed these 2 rows to correct the concatenation
echo '<img src="images/"' . $row["image"] . '">';
echo '<img src="images/"' . $row["image"] . '">';
}
?>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
hey guys i am stuck at very end point of my code , my aim was to Store image path to database and store the image to a directory. and than i want to show those images.
i am successfully done uploading part but now i am stuck how can i show those images on my webpage, here is my code
<?php
$sql = "SELECT * FROM pictures";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_array($result,MYSQLI_ASSOC);
while($row = mysqli_fetch_array($result))
{
$image_path=$row["folder_name"];
$image_name=$row["picture_name"];
echo "img src=".$image_path."/".$image_name." width=100 height=100";
}
?>
If you want to fetch associative arrays, use fetch_assoc instead, your $data is not needed here, it's simpler at the end. Also, only select the fields you need in your query. To fix your problem, You are simply missing the HTML , try this:
<?php
$sql = "SELECT folder_name, picture_name FROM pictures";
$result = mysqli_query($conn, $sql);
if(!$result) {
die("Error with your Query: " . mysqli_error($conn));
}
while($row = mysqli_fetch_assoc($result)) {
$image_path = $row["folder_name"];
$image_name = $row["picture_name"];
echo "<img src=\"" . $image_path . "/" . $image_name . "\" width=\"100\" height=\"100\"></img>\n";
}
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My search is running perfectly but I need to link each result to a description page. Any ideas as to how to do it?
<?php
session_start();
require_once 'login.php';
$conn = mysqli_connect($server,$user,$password,$dbase);
if(!$conn){
die("Failure to connect".mysqli_connect_error());
}
$id = $_SESSION['twitcher'];
$srch = $_POST['searchstr'];
$sql = "select * from gallery where title like '%$srch%'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result) > 0){
while ($rows=mysqli_fetch_assoc($result)){
echo $rows['title'].$br.$br;
}
}else echo "No posts found.";
mysqli_close($conn);
?>
Exactly as #Dagon stated: You need to simply echo out a link tag (<a>)
while ($rows=mysqli_fetch_assoc($result)) {
echo "<a href='/link_to_where_you_want_to_go'>" . $rows['title'] . "</a>" . $br . $br;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
At bottom of INSERT php/sql code, i use echo to print out query result to fix errors, in this way:
... code ...
$result = MYSQL_QUERY($sqlQuery);
echo $sqlQuery
Exist a solution to print out UPDATE and DELETE queries like above?
TKS All
Based on the comments to OP, you need to change the way you run the query if you want this to work. Below is how I would've done it.
$update = "UPDATE mod_document_images SET image_os_res = '" . $checkbox_os . "', image_ne_aut = '" . $checkbox_ne . "', image_ge_cat = '" . $image_gen_cat . "' WHERE image_id = " . $image_id;
echo "Query: " . $query; // Echo the query containing the variables supplied
$result = mysql_query($update); // Run the update and store the result in $result
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have 2 php files that retrieve a BLOB image from mysql DB. My DB has stored a couple of different images, as i try to display them on the browser, only the first image is displayed multiple times, for example: The DB table has stored 5 images, the browser is going to display the first image 5 times.
here is a snippet from my main php file:
$strSQL = "SELECT * FROM images";
$rs = mysql_query($strSQL) or die (mysql_error());
echo "<table>";
while($row = mysql_fetch_array($rs)) {
echo "<tr><td>";
echo " <img src=load_pic.php?id=".$row["id"]." id='img' width='100' height='100'></a>";
echo "</td></tr>";
}
echo "</table>"
and the php file that gets the images "load_pic.php"
$q="select * from images";
$rec=mysql_fetch_array(mysql_query($q));
$data=$rec['image'];
header('Content-Length: '.strlen($data));
header("Content-type: image/".$rec['type']);
echo $data;
Your load_pic.php script is not using the id parameter. It should be:
$q = "select * from images where id = " . mysql_real_escape_string($_GET['id']);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hello i am beginner to PHP.I am not getting an idea regarding how to get all the rows as an output in the form of anchor tags .Here is my following code where blogtable is the name of the table . For instance i have five rows in a table . I want the entire rows as links as a resultant.By executing the following code i am getting the records in a table but unable to transform these results into anchor tags.Kindly suggest me an idea to get each and every row in the form of anchor tag.Thanks in advance.
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("test");
$data = mysql_query("select * from blogtable");
while ($col = mysql_fetch_field($data)) {
echo $col->name;
}
while ($row = mysql_fetch_row($data)) {
for ($i = 0; $i < count($row); $i++) {
echo"<br/>";
echo"$row[$i]></a>";
echo"<br/>";
}
}
?>
Just add your link inside the for loop:
echo "<a href='http://example.com'>" . $row[$i] . "</a>";
Try this: echo "".$row[$i]."";
echo"$row[$i]></a>;
This is not the correct syntax for an anchor tag. Try something like:
echo "<a href='some site'>$row[$i]</a>";