0
我的實驗室的目的是讓用戶通過名爲「pageVistis」的數據庫搜索他們在該字段中輸入的內容。他們可以搜索遠程主機或頁面名稱。我一直無法解決一個錯誤,我收到說:「注意:未定義變量:searchtype在C:\ xampp \ htdocs \ pageVisitsLab \ DataBC.php在線23mysql數據庫搜索遠程主機或頁面名稱
致命錯誤:未捕獲錯誤:調用成員函數bind_param()在C:\ xampp \ htdocs \ pageVisitsLab \ DataBC.php中的布爾值中:25堆棧跟蹤:#0 {main}在第25行的C:\ xampp \ htdocs \ pageVisitsLab \ DataBC.php中拋出。該代碼也形成一個名爲「DataBC.php」的文件。如果需要任何額外的信息,請讓我知道,我將編輯這篇文章,幷包括它謝謝你。
include "interface.php";
if(isset($_POST['submit'])) {
$sName = $_POST['sN'];
$sHost = trim($_POST['sH']);
if(!$sName || ! $sHost) {
echo "<p> Please enter a search </p>";
exit;
}
/*switch ($sName) {
case 'sName':
case 'sHost':
break;
default:
echo "<p> Invalid search type and please try again </p>";
}
*/
$query = "SELECT page_name, visit_date, previous_page, request_method, remote_host, remote_port FROM visitInfo
WHERE $searchtype= ?";
$stmt = $databse -> prepare($query);
$stmt-> bind_param('s',$sName);
$stmt-> execute();
$stmt->store_result();
$stmt->bind_result($pageName,$visitDate,$previouPage,$requestMethod,$remoteHost,$remotePort);
echo "<p> The number of items found: .$stmt->num_rows</p>";
while ($stmt->fetch()) {
echo "<p><strong>page Name: ".$pageName."</strong></p>";
echo "Visit Date: ".$visitDate."<br>";
echo "Previous Page: ".$previouPage. "<br>";
echo " Request Method: ".$requestMethod. "<br>";
echo "Remote Host: ".$remoteHost. "<br>";
echo "Remote Port: ".$remotePort. "<br>";
}
$stmt->free_result();
$databse->close();
}
?>
在嘗試使用它之前,您還沒有定義_like錯誤says_'$ searchtype' – RiggsFolly