幾分鐘前,我在這裏提出了一個關於被排序的語法錯誤的問題。我需要獲得幫助才能使這個腳本工作,或者至少讓某人指向正確的方向。來自HTML表格的PHP搜索代碼
這是一個搜索腳本,可通過多個字段進行搜索。搜索()陣列工作正常,是一系列tickboxes與下面的代碼:
<td width="22"><input type="checkbox" name="search[olevel = 'Yes']" id="search[olevel = 'Yes']" value="1"/>
郵政編碼框是用下面的代碼文本框:
<input name="postcode[]" type="text" id="postcode[]" size="12" maxlength="12" /></td>
當我打勾的olevel箱它將返回olevel字段中包含「是」的所有記錄。這符合我的預期。
如果我在郵編中輸入任何內容,它將不會返回任何結果。
這裏是搜索引擎的php代碼。
<?php
include ('c1.php');
if ($_COOKIE["auth"] == "1") {
$display_block = "<p>You are an authorized user.</p>";
} else {
header("Location: userlogin.html");
exit;
}
doDB();
$display_block = "<h1>Results</h1>";
if (isset($_POST['search']) && !empty($_POST['search'])) {
foreach ($_POST['search'] as $key => $value) {
if ($value == 1)
$search[] = "$key";
$searchstring = implode(' AND ', $search);
$post_map = array(
'postcode' => 'candididate_contact_details.postcode'
);
}
if (isset($_POST['postcode']) && !empty($_POST['postcode'])) {
foreach ($_POST['postcode'] as $key => $value) {
if (array_key_exists($key, $post_map))
$search[] = $post_map[$key] . '=' . mysql_real_escape_string($value);
echo $searchstring;
echo $search;
$query = "SELECT candidate_id.master_id, candidate_contact_details.first_name, candidate_contact_details.last_name, candidate_contact_details.home_phone, candidate_contact_details.work_phone, candidate_contact_details.mobile_phone, candidate_contact_details.email FROM candidate_id, candidate_contact_details, qualifications, security_experience, previous_career WHERE qualifications.active = 'finished' and candidate_id.master_id = candidate_contact_details.master_id and candidate_id.master_id = qualifications.master_id and candidate_id.master_id = security_experience.master_id and candidate_id.master_id = previous_career.master_id and $searchstring";
$query_res = mysqli_query($mysqli, $query)
or die(mysqli_error($mysqli));
// $search = mysqli_query($mysqli, $query)or die(mysqli_error($mysqli));
{
$display_block .= "
<table width=\"98%\" cellspacing=\"2\" border=\"1\">
<tr>
<th>Registration Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Home Number</th>
<th>Work Number</th>
<th>Mobile Number</th>
<th>E-Mail</th>
</tr>";
while ($result = mysqli_fetch_array($query_res)) {
$regnum = $result['master_id'];
$first_name = $result['first_name'];
$last_name = $result['last_name'];
$home_phone = $result['home_phone'];
$work_phone = $result['work_phone'];
$mobile_phone = $result['mobile_phone'];
$email = $result['email'];
$display_block .= "
<tr>
<td align=\"center\">$regnum <br></td>
<td align=\"center\">$first_name <br></td>
<td align=\"center\">$last_name <br></td>
<td align=\"center\">$home_phone <br></td>
<td align=\"center\">$work_phone <br></td>
<td align=\"center\">$mobile_phone <br></td>
<td align=\"center\">$email <br></td>
</tr>";
}
$display_block .= "</table>";
}
}
}
}
?>
<html>
<head>
<title> Display results</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>
我知道我做錯了什麼,但無法弄清楚。提前致謝。
'name =「search [olevel ='Yes']」'我不認爲這是一個有效的名字,有人將不得不支持我。 – JohnD
這是目前有效的部分。試圖解決這個問題,因爲迄今爲止我發現的所有搜索示例腳本都處理數據庫中的1個字段或全部這些字段。 –
但是你爲什麼要用'search [olevel ='是']'?不僅僅是「搜索[1/0]」還有效嗎?我只是問,因爲這些事情有時會在分析程序無法正確識別它的情況下在場景後面打破腳本。 – Naltharial