我已閱讀有關此主題的許多問題,但未找到答案。 我有一個錯誤Notice: Undefined index: searchText in C:\xampp\htdocs\twitter\lib\search.php on line 5
不知道爲什麼......
HTML表單:
<div id="search" class="fleft">
<form name="tsearch" action="lib/search.php" method="post">
<input type="text" name="searchText" placeholder="Search tweet!">
<input type="submit" name="search" value="Search"/>
</form>
</div>
和PHP腳本,我要送,但不獲取數據
全部sript的一部分。 更新:
<?php
include "connect.php";
//session_start();
if (isset($_POST['searchText'])){
//echo '<pre>'; print_r($_REQUEST); echo '</pre>';
$query = "SELECT u.nickname, t.text, t.pubdate FROM 111212_tweets t INNER JOIN 111212_users AS u ON t.user_id = u.id WHERE t.text LIKE '%" . $_POST['searchText'] . "%' ORDER BY t.pubdate DESC";
$_SESSION['searchQuery'] = $query;
header('Location: ../main.php');
}else {
$query = "SELECT u.nickname, t.text, t.pubdate FROM 111212_tweets t INNER JOIN 111212_users AS u ON t.user_id = u.id ORDER BY t.pubdate DESC";
$_SESSION['searchQuery'] = $query;
}
?>
你檢查看看你的表單是否已經提交,然後再檢查if($ _POST ['searchText'])'? – andrewsi
'if(isset($ _ POST ['searchText']))' – bansi