我想使用处于选中状态的复选框更新数据库。
仅选中要更新的复选框。
<?php
$sql = mysqli_query($conn, "SELECT * FROM leads ORDER BY lid ASC");
if($count = mysqli_num_rows($sql) == 0){
echo '<tr><td colspan="8">No Data Entry</td></tr>';
}else{
while($row = mysqli_fetch_assoc($sql)){
echo '
<tr>
<td> <input name="checkbox[]" value="'.$row['lid'].'" type="checkbox"></td>
<td>'.$row['name'].'</td>
<td>'.$row['gender'].'</td>
<td>'.$row['phone'].'</td>
<td>'.$row['company'].'</td>
<td>'.$row['vehicle'].'</td>
</tr>
';
}
}?>
这是我的选择代码
<select name="name" class="form-control" onchange="form.submit()">
<option value="0">Filter Data Member</option>
<?php
$sql = mysqli_query($conn, "SELECT * FROM list ORDER BY uid ASC");
if($count = mysqli_num_rows($sql) == 0){
echo '<tr><td colspan="8">No Data Entry</td></tr>';
}else{
while($row = mysqli_fetch_assoc($sql)){
echo '<option name="name" value="'.$row ['name'].'">'.$row ['name'].'</option>
';
}
}?>
这是我的更新
<?php
if( isset($_POST['submit']) & empty($_POST["checkbox"]) ) {
echo'<div class="alert alert-warning alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <strong>Oops!!</strong> Please select atlest one.</div>'; }
elseif(isset($_POST['submit']) & !empty($_POST["checkbox"]) ){
$name = $_POST['name'];
for($i=0;$i<count($_POST['checkbox']);$i++){
$trans_id=$_POST['checkbox'][$i];
$sql = "UPDATE leads SET luser='$name' ";
$result = mysqli_query($conn,$sql) or die(mysqli_error());
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=trans.php\">";
}}?>
使用此代码我的更新执行工作但我的问题不仅仅是复选框更新,而且所有数据库表列表都同时更新。
感谢任何形式的帮助或建议。谢谢......