0
我試圖創建一個搜索引擎,將從mySQL數據庫中提取信息。我的代碼如下:WAMP服務器不允許php搜索引擎?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Search Engine Test</title>
</head>
<body>
<script language="php">
// Create a database connection
$connection = mysql_connect("localhost", "root", "", "test");
if (!connection) {
die("Please reload page. Database connection failed: " . mysql_error());
}
// Select a databse to use
$db_select = mysql_select_db("test", $connection);
if (!$db_select) {
die("Please reload page. Database selection failed: " . mysql_error());
}
// Search Engine
// Only execute when button is pressed
if (isset($_POST['keyword'])) {
// Filter
$keyword = trim($_POST['keyword']);
// Select statement
$search = "SELECT Price FROM 'table_1' WHERE * LIKE '%$keyword%'";
// Display
$result = mysql_query($search) or die('query did not work');
while ($result_arr = mysql_fetch_array($result)) {
echo $result_arr['*'];
echo " ";
echo "<br>";
echo "<br>";
}
$anymatches = mysql_num_rows($result);
if ($anymatches == 0) {
echo "Nothing was found that matched your query.<br><br>";
}
}
</script>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="text" name="keyword">
<input type="submit" name="search" value="Search">
但是,當我運行它時,我收到一條通知,說我被禁止訪問服務器。任何幫助,將不勝感激。
你能在這裏粘貼錯誤嗎? – Ibu
可能是一個httpd.conf問題。 – dnelson
'wwhile'應該是'while'。我已經修復它假設它只是一個錯字。 – Tiny