我正在尝试使用联系人搜索选项,现在我正在尝试根据选中的复选框更改查询。这是我的代码,请告诉我我在做什么错。
表格
<form method = 'post'>
<input type="checkbox" name="contactfilter[]" value="all">All Contacts<br>
</input>
<input type="checkbox" name="contactfilter[]" value="mine">My Contacts<br>
</input>
<button type="submit" value="submit"></button>
</form>
PHP代码
<?php
if(isset($_POST['submit'])) {
$contactfilter = $_POST['contactfilter'];
$service_list = array();
if(in_array('all', $contactfilter)) {
$service_list[] = 'all';
$mine = '';
}
if(in_array('mine', $contactfilter)) {
$service_list[] = 'mine';
$mine = " where contact_owner = '".$_SESSION ["username"]."'";
}
}
$query = "select contact_id, first_name, last_name, company_name,
company_description, position, company_address, company_phone, home_phone,
cell_phone, work_phone, email, how_they_heard, date, time from contact
//im attempting to fill the query with the $mine variable
".$mine."";
$result = mysqli_query($connect, $query);
//this section echo's all data that matches the query
while($row = mysqli_fetch_array($result))
{
echo '
<tr id ="table">
<td data-url="contact_interface.php?contact_id=' . $row['contact_id'] .
'">'.$row["first_name"].'</td>
<td data-url="contact_interface.php?contact_id=' . $row['contact_id'] . '"
type="text" name="last_name">'.$row["last_name"].'</td>
<td data-url="contact_interface.php?contact_id=' . $row['contact_id'] . '"
type="text" name="home_phone">'.$row["home_phone"].'</td>
etc.......
';
}
?>