你好,我在这项任务中遇到了很大的问题
我在xampp上建立了一个名为search_test的数据库,其中有名字和姓氏作为字段。我已经设置了一个php表单,这样当用户输入一个名字时,比如说Andre,它会返回数据库中的所有andres。有一个问题,它一直告诉我没有搜索结果,即使我知道数据库里有数据,这里的代码应该是一个叫做index.php的php页面
<?php
mysql_connect("localhost","michael","xcA123sd") or die(mysql_error());
mysql_select_db("search_test") or die ("could not find db");
$output ='';
if (isset ($_POST['search']));
$searchq = $_POST['search'];
$query = mysql_query("SELECT * FROM members WHERE firstname LIKE '%searchq%'" ) or die("could not search");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search results !';
}else{
while($row = mysql_fetch_array($query)){
$fname = $row['firstname'];
$output .='<div> '.$fname.'</div>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>search</title>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="search" placeholder="search for members"/>
<input type="submit" value=">>"/>
</form>
<?php print("$output);?>
</body
</html> 例如,我键入andre in,就会得到响应
没有搜索结果!
有没有人能帮帮忙
发布于 2013-04-01 00:18:29
问题来自您代码的这一行
$query = mysql_query("SELECT * FROM members WHERE firstname LIKE '%searchq%'“)
变量searchq后面没有$
https://stackoverflow.com/questions/15731470
复制相似问题