doushai4890 2018-10-26 21:04
浏览 14

尝试根据所选复选框更改查询[重复]

This question already has an answer here:

I'm trying to make a contact search option, right now i'm trying to change a query based on whichever checkbox is selected. Here is my code, please tell me what I'm doing wrong.

FORM

<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 CODE

<?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.......
  ';      
 }  
 ?>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度