我的代码中有一个小问题,我无法弄清楚它是什么..
我正在尝试用PHP制作一个示例搜索引擎工具,一切正常,直到我试图从数据库中搜索一些帖子...当我这样做时,它说我没有$ header和$生物宣布...
<?php
include('connection.php');
$query =mysqli_real_escape_string($dbc, $_POST['query']);
$q = mysqli_query($dbc, "SELECT id FROM search WHERE header LIKE '%$query%' OR bio LIKE '%$query%'");
$num = mysqli_num_rows($q);
echo $num;
if(!$query){
echo "Enter a query...";
} else {
if($num != 0)
{
echo "<hr>";
while ($fetch = mysqli_fetch_assoc($q)){
$id = $fetch['id'];
$header = $fetch['header'];
$bio = $fetch['bio'];
echo "<strong>" . $header . "</strong>";
echo "<blockquote><p>" . $bio . "</p></blockquote>";
echo "<hr>";
}
} else {
echo "No results where found .. ";
}
}
?>
和表格
<div style = "width:300px; margin:auto;">
<h1> Add Search Criteria</h1>
<p> Type a header and bio below to add to search engine</p>
<p>
<input id="header" name = "header" type="text" placeholder="header" style="width:100%;">
</p>
<p>
<textarea id="bio" name="bio" cols="40" rows="7" placeholder="Write a bio.."></textarea>
</p>
<p>
<center>
<button id="submit">Submit Search</button>
</center>
</p>
<div id="add_error" style="text-align:center"></div>
<hr>
<h1>Search The Database</h1>
<p>Please type something to search to database</p>
<p>
<input name = "query" id="query" type="text" placeholder="search">
<button id="search">Search</button>
</p>
<div id="search_error">
</div>
</div>
这是它的输出
注意:未定义的索引:第25行的C:\ wamp64 \ www \ mywebsite \ Search \ search.php中的标题 调用堆栈
1 0.0021 242472 {main}()... \ search.php:0
(!)注意:第26行的C:\ wamp64 \ www \ mywebsite \ Search \ search.php中的未定义索引:bio 调用堆栈
1 0.0021 242472 {main}()... \ search.php:0
答案 0 :(得分:1)
在您选择的查询中添加标题和生物列。
$q = mysqli_query($dbc, "SELECT id, header, bio FROM search WHERE header LIKE '%$query%' OR bio LIKE '%$query%'");