多个选择只插入一个值

时间:2018-04-02 14:09:27

标签: php mysql

for循环只更新一条记录。好像它没有增加。

 <label for='Keys[]'>Select Keys</label>
<select multiple="multiple" name="Keys[]">
<?php
echo "<option value=''>Select A Key</option>";
$codesQuery=mysqli_query($DBcon,"SELECT * FROM Codes where Status != 'Used' AND UserID ='$ID'");
while($codes=mysqli_fetch_assoc($codesQuery))
{
echo "<option value='$codes[Value]'>$codes[Value]</option>";
}
?>
</select>      


$i=1;
    foreach ($_POST['Keys'] as $row => $printd) {
        $print_dim = $printd;
        $method = $_POST['method'][$row];

    $sql2 = "UPDATE `Codes` SET `Status`= 'Used' WHERE `Value` = '$print_dim'";



    enter code here

      $i++;
    }

1 个答案:

答案 0 :(得分:0)

好的,所以想出来..需要把我的查询执行到我的循环中......

    foreach ($KeysS as $t) {

    echo "$t <br>";
  $sql2 = "UPDATE `Codes` SET `Status`= 'Used' WHERE `Value` = '$t'";
    if ($DBcon->query($sql2) === TRUE) {
         echo "Record updated successfully <br>";
    } else {
         echo "Error updating record: <br>" . $DBcon->error;
    }
}