如果在PHP

时间:2016-08-08 17:19:23

标签: php mysql

在我的代码中,我有它,以便它将显示一行mysql,最后我有一个输入来放入一个日期,然后将其插入数据库。我无法弄清楚如何制作它以便它使用每个选中的行行单独更新每个输入。

$i = 0;
while($row = $result->fetch_assoc()) {
   echo  "<div class='row'>
    <div class='col-md-10 col-offset-1'>
    <tr>
    <td>
    <input type='checkbox' name='chk1[$i]' value='".$row['customerid']."' /> " .$row['firstname']." ".$row['lastname']. 
    "</td>
    <td>"  .
    $row['phonenumber'].
    "</td> 
    <td>" .$row['brand'].
    "</td>
    <td>" .$row['stock'].
    "</td>
    <td>" .$row['shoename'].
    "</td>
    <td>" .$row['size'].$row['width']. "</td>"; 
    echo "<td><input name='backorder' type='date'/></td>
    <td id='comments'>" .$row['comment']. "</td> 
    </div>
    </div>";
$cid[$i] = $row['customerid'];
$i++;
}

因此,当我使用下面的更新时,它会更新所有内容,但会为数据库中的所有行提供相同的延期交货值。

if(isset($_POST['chk1'])) {
    foreach($_POST['chk1'] as $cid[$i]) {
        $chk1[] = array($cid[$i]);
        if(!empty($chk1)) {

            //include("email.php");
            $sql = "SELECT * FROM shoes WHERE customerid =" .$cid[$i];
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    $texting = $row['texting'];
                    $name = $row['firstname'];
                    $email = $row['email'];
                    $provider = $row['provider'];
                    $brand = $row['brand'];
                    //$sql must be in this loop in order to execute all checkboxes.

                    $sql = "UPDATE shoes SET ordered=CURDATE(), backorder='backorder' WHERE customerid=".$cid[$i];

1 个答案:

答案 0 :(得分:0)

您的SQL为该字段的更新发送静态字符串值。

$sql = "UPDATE shoes SET ordered=CURDATE(), backorder='backorder' WHERE customerid=".$cid[$i];需要更新以使用值变量或字符串&#34; backorder&#34;将成为任何更新的价值。