文君想請教一下,
我在myAdmin建立一資料庫名為 "temple"
裡面的資料表名為"temple-tot"
欄位共有下列7個:id,name,country,place,info,http_addr
除了第一欄位之外,其它欄位皆可供人查詢.
我照您所告知的程式,填了相關的內容,但是查詢出來結果是說:網頁無法顯示".
不知是哪裡寫錯了?(以下是假設開放name及info這兩個欄位供人查詢)
是不是$query 寫錯了?
<?php
//------[基本設定 ]-------
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = "temple";
//-------
if ( isset($http_post_vars['searchtext']) ){ //有輸入搜尋文字
$searchtext = $http_post_vars['searchtext']; //將變數searchtext指定為由post標準輸入的searchtext值
$my_db = mysql_connect("localhost","root"); //連結sql
mysql_select_db("temple"); //選擇資料庫
$query = "SELECT `name` , `info` FROM `temple-tot` WHERE `name` LIKE $searchtext AND `info` LIKE $searchtext "; //這裡請自己應用
$result = mysql_query($query, $my_db); //送出mysql命令
$err = mysql_error(); //取的錯誤狀況
if ($err){die("錯誤發生<br>錯誤指令:".$query."<br>錯誤訊息".$err);} //中斷程式並顯示錯誤訊息
if ( mysql_num_rows($result) != 0 ){ //表示有傳回資料
while( $res = mysql_fetch_array($result) ) //傳回陣列資料
{
//這邊顯示搜尋結果
}
}else{ //表示找不到資料
//這邊顯示沒有符合的資料
}
}else{ //沒有輸入文字
echo "<html>
<body>
<form action=./blank method=\"post\">
搜尋列 <input type=\"text\" name=\"searchtext\">
<select name=\"kind\">
<option vlaue=\"homepage\">個人網站</option>
<option vlaue=\"picture\">圖片</option>
<option vlaue=\"news\">新聞</option>
</form>
</body>
</html>";
}
?>