php 查询数据库页面输出问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 07:11:38
数据库设计以及连接都没问题,查询代码如下:
<?
if($_POST)
{
$name = $_REQUEST['name'];
$conn = mysql_connect("localhost","root","19880402");
$result = mysql_db_query("image","select explanation from union where name='$name'",$conn);
mysql_query("set names gb2312");
while($row = mysql_fetch_array($result))
{
$array[]=$row;
}
mysql_free_result($result);
if(count($array))
{
header("Location: lookout.php");
}
else
{
echo "该城市不存在!";
}

}

?>

<form id="form1" name="form1" method='post' action="">
<table align="center">
<tr>
<td>城市:</td>
<td><input name="name" type="text"></td

"select explanation from union where name='$name'"

这个查询语句是错的,没有表

应该是你SQL语句那块的表名和字段名出错了!

mysql_query("set names gb2312");这句话要写在连接数据之后,你现在写的地方会不起作用.
$result = mysql_db_query("image","select explanation from union where name='$name'",$conn);这句话.第一个是库名!第二个是SQL语句,第三个连接资源.这里表和字段一定保证没有问题
试着输出一个$result.看返回是不是一个资源

mysql_db_query:自 PHP 4.0.6 起不提倡使用此函数。不要用此函数,用 mysql_select_db() 和 mysql_query() 来替代。