本質上,我試圖使用數組更新多個MySQL行,我從$_POST
變量中獲得了一個名爲「units」的變量。一直試圖弄清楚這一點。這是我到目前爲止有:
目前代碼,這並不添加到第二個人:
if(isset($_POST['unit'])){ $units .= implode(', ', $_POST['unit']); } else { redirect('addcall.php?err=7'); }
$my_s = $my->prepare('INSERT INTO `calls`(`call_taker`, `call_time`, `call_type`, `call_priority`, `call_location`, `call_city`, `reporter_name`, `reporter_num`, `call_info`, `units`) VALUES (?,?,?,?,?,?,?,?,?,?)') or die($my->error);
$my_s->bind_param('sssisssiss', $name, $date, $c_type, $c_prio, $c_loc, $c_city, $r_name, $r_num, $c_info, $units) or die($my->error);
$my_s->execute() or die($my->error);
$my_s->close();
$my->close();
$my = new mysqli(HOST, USER, PASS, DB);
$my_s2 = $my->prepare('UPDATE `users` SET `busy` = 1 WHERE `badge` = ? AND `enabled` = 1 AND `confirmed` = 1 AND `duty` = 1') or die($my->error);
$my_s2->bind_param('s', $units) or die($my-error);
$my_s2->execute() or die($my-error);
$my_s2->close();
$my->close();
redirect('dashboard.php');
<table> // table for checkboxes thats in main HTML area
<tr> <td>Units Available:   </td>
<?php
$my = new mysqli(HOST, USER, PASS, DB);
$my_s = $my->prepare('SELECT `name`, `badge` FROM `users` WHERE `duty` = 1 AND `busy` = 0');
$my_s->execute();
$my_s->store_result();
if($my_s->num_rows == 0){
echo "<td>None</td>";
}
$my_s->bind_result($u_name, $u_badge);
while($row = $my_s->fetch()){
echo '<td><input type="checkbox" name="unit[]" value="'.$u_badge.'">'.$u_name.' , #'.$u_badge.' </td>';
}
$my_s->close(); $my->close();?>
</tr>
</table>
你爲什麼要把'#'放在值的前面?如果你沒有這樣做,你可以使用後值作爲數據插入到數據庫中。 – Barmar
哦,如果沒有#值,我可以直接發送直接後續數據,它會更新每個分配給其「忙」列的用戶? – CaptainThrills
沒有更改第二個用戶繁忙的列。只改變了第一個。還必須添加一些重要的檢查,因爲它被添加到每個人,但第二人 – CaptainThrills