繁体   English   中英

无法在网页上显示图像,图像路径存储在数据库中

[英]Cant display images on web page, where image path is stored in database

我正在尝试在网页上显示图像,其中图像路径存储在数据库中,图像存储在服务器中。但是我无法使用以下代码显示这些图像,因此请有人帮助我解决这个问题。

<form method="post"  enctype="multipart/form-data" action="file_upload.php">
<table>

<?php

$dbhost = 'xxxxxxxx';
$dbuser = 'xxxxxxxxx';
$dbpass = 'xxxxxxxxxx';
$db_name = 'xxxxxxxxxx';
$tbl_name = 'xxxxxxxxxxx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db_name")or die("cannot select DB");

$query1 = mysql_query("select * from '$tbl_name' where id='1'");
$rows1 = mysql_fetch_array($query1);
$path1 = $rows1['image'];

$query2 = mysql_query("select * from '$tbl_name' where id='2'");
$rows2 = mysql_fetch_array($query2);
$path2 = $rows2['image'];

$query3 = mysql_query("select * from '$tbl_name' where id='3'");
$rows3 = mysql_fetch_array($query3);
$path3 = $rows3['image'];

echo '<tr><td><img src="$path1"></td>' ;
echo '<td><img src="$path2"></td>' ;
echo '<td><img src="$path3"></td></tr>' ;

?>

</form>
</table>

输出仅打印$ path1,$ path2和$ path3,.. /

在此处输入图片说明

像这样更改您的查询

他们全部

 $query1 = mysql_query("select * from ".$tbl_name." where id='1'") or die(mysql_error());

您正在传递$ path变量作为字符串更改,

像这样

echo "<tr><td><img src='".$path1."'></td>";

请更正以下行:

echo "<tr><td><img src='$path1'></td>" ;
echo "<td><img src='$path2'></td>" ;
echo "<td><img src='$path3'></td></tr>" ;  

它关于报价:)

使用HTML + PHP之类的

<tr><td><img src='<?php echo $path;?>'></td>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM