我试图在网页上显示图像,其中存储在数据库和图像中的图像路径存储在server.But中,但我无法使用以下代码显示这些图像,所以请有人帮助我这个问题..从数据库显示图像路径时出错
<form method="post" enctype="multipart/form-data" action="file_upload.php">
<table>
<?php
$dbhost = 'xxxxxxxx';
$dbuser = 'xxxxxxxxx';
$dbpass = 'xxxxxxxxxx';
$db_name = 'xxxxxxxxxx';
$tbl_name = 'imagetype1';
$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'"); //Error
$rows1 = mysql_fetch_array($query1);
$path1 = $rows1['image'];
$query2 = mysql_query("select * from '$tbl_name' where id='2'"); //Error
$rows2 = mysql_fetch_array($query2);
$path2 = $rows2['image'];
$query3 = mysql_query("select * from '$tbl_name' where id='3'"); //Error
$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>
错误
您的SQL语法错误;检查对应于你的MySQL服务器版本使用附近的'imagetype1' 正确的语法手册其中id =在行‘1’“1
什么是表imagetype1列ID的数据类型? – Simon 2014-10-22 07:07:07
删除所有''$ tbl_name''上的引号,这些不是正确的标识符。 – 2014-10-22 07:10:04
试试这个:“select * from {$ tbl_name} where id ='1'”...当您在双引号字符串中使用{$ somevar}时,您的变量名称将被展开...更多信息是http:// php。 net/manual/en/language.types.string.php#language.types.string.parsing – vsingh 2014-10-22 07:12:10