我正在尝试在网页上显示图像,其中存储在数据库和图像中的图像路径存储在服务器中。但是我无法使用以下代码显示这些图像,所以请有人帮我解决这个问题,..
<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行
答案 0 :(得分:2)
更改
mysql_query("select * from '$tbl_name' where id='1'");
到
mysql_query("select * from ".$tbl_name." where id='1'");
答案 1 :(得分:0)
不要在查询中使用围绕表名的引号字符(&#39;)。