这是我的PHP代码:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'moviefone';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $con); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $output = '';
if (isset($_POST["search-text"])) {
$searchq = $post["search-text"];
$searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
$query = mysql_query("SELECT * FROM movies WHERE title LIKE '%$searchq'") or die("could not search");
$count = mysql_num_rows($query);
if ($count == 0) {
$output = "no result found";
} else {
while ($row = mysql_fetch_array($query)) {
$title = $row['title'];
$images = $row['images'];
$output .= '<div>' . $images . ' ' . $title . '</div>';
}
}
}
?>
这是我的HTML表单:
<form id="frm-search" action="search.php" method="post">
<div class="m-search">
<input type="hidden" id="search-text-value" name="search-text-value">
<input type="text" id="search-text" maxlength="150" class="search-text" name="search-tex" placeholder="search" value="" autocomplete="off" onblur="" style="color: rgb(140, 140, 140);">
<input type="image" src="spray/search.png" value="" class="search-btn">
<div class="clear"> </div>
</div>
</form>
我无法显示任何结果,并且页面上没有显示错误。我无法找出我做错了什么。
答案 0 :(得分:1)
多个错别字:
if (isset($_POST["search-text"])) {
$searchq = $post["search-text"];
^^^^^---should be $_POST
^^^^^^^^^^---wrong field name, see below
然后在你的HTML中:
[..snip...] class="search-text" name="search-tex" [...snip...]
^^^^^^^^^^---must match the above code