【发布时间】:2017-04-29 18:24:44
【问题描述】:
所以,我想制作自己的搜索引擎,通过在搜索框上键入标题来查找数据,并从我的数据库和输出中获取数据,就像用户在搜索框中输入的内容一样......所以这是我的代码: 1. HTML 代码(搜索框)
<form id="hform-search" class="hform-search" method="post" action="">
<input id="search-box" class="form-control" type="text" placeholder=" I want to learn.." name="keyword" autocomplete="off" autofocus="" />
<div id="suggesstion-box"></div>
<input type="submit" class="btn btn-default f-tutorials" name="go_t" value="Find Tutorials" />
<input type="submit" class="btn btn-default f-course" name="go_c" value="Find Courses" />
<p class="hero-subtitle"><em>"Let us help you to involve"</em> </p>
</div>
</form>
-
PHP 代码
$conn = mysqli_connect("localhost","root","","neurorial"); if ($_POST[go_t] == 'Find Tutorials') { $keyword_t = $_POST[keyword]; $find_t = mysqli_query($conn, "SELECT * FROM search WHERE video_tutorial LIKE '%$keyword_t%' "); $check_t = mysqli_num_rows($find_t); if ($check_t == 0) { echo 'sorry the video with this " $keyword_t " keyword is not found'; }else { while ($rows_t=mysqli_fetch_array($find_t) ) { echo "$rows_t[video_tutorial]<br>"; } } } if ($_POST['go_c'] == 'Find Courses') { global $conn; $keyword_c = $_POST['keyword']; $find_c = mysqli_query($conn, "SELECT * FROM search WHERE course LIKE '%$keyword_c%'"); $check_c = mysqli_num_rows($find_c); if ($check_c == 0) { echo "maaf pencarian Course dengan keyword $keyword_c tidak di temukan"; }else { while ($find_c = mysqli_fetch_array($find_c) ) { echo "$find_c[course]<br>"; } } }
然后我总是得到这个结果:
注意:使用未定义的常量 go_t - 在第 87 行的 D:\KAMPUS\Server\htdocs\PW\Neuro.inc\index.php 中假定为“go_t”
注意:未定义索引:第 87 行 D:\KAMPUS\Server\htdocs\PW\Neuro.inc\index.php 中的 go_t
注意:未定义的索引:第 100 行 D:\KAMPUS\Server\htdocs\PW\Neuro.inc\index.php 中的 go_c
谁能解决这个问题并告诉我为什么我总是得到这个错误? 提前致谢! :)
【问题讨论】:
标签: php html mysqli search-engine