第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

PHP MySQL 使用復(fù)選框更新多行

PHP MySQL 使用復(fù)選框更新多行

PHP
胡子哥哥 2021-11-05 10:38:15
我想用 PHP 更新 MySQL 中的檢查值<?phprequire "../../../../config.php";if (isset($_POST['btn-upload'])) {    try {        $connection = new PDO($dsn, $username, $password, $options);        $status = $_POST['status'];        $ck_id = $_POST['ck_id'];        for ($i = 0; $i < sizeof($ck_id); $i++) {            $sql = "UPDATE form_eg208 SET status=:status where ck_id IN (:ck_id)";            $statement = $connection->prepare($sql);            $statement->bindParam(':status', $status[$i]);            $statement->bindParam(':ck_id', $ck_id[$i]);            $statement->execute();        }    } catch (PDOException $error) {        echo $sql . "<br>" . $error->getMessage();    }    if ($statement->rowcount() >= 0) {        echo '<div class="alert alert-success alert-dismissible" id="flash-                 msg">    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;                     </a>                  <h4> <strong>Success!</strong> Insert Record                   Successfully</h4>                  </div>';    } else {        echo '<div class="alert alert-danger alert-dismissible" id="flash-                    msg">    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;                          </a>                 <h4> <strong>Failed!</strong> Duplicate BGLPARTNO</h4>                    </div>';    }}?>我的 html 代碼是<?php$id = $_REQUEST['cid'];try {    $connection = new PDO($dsn, $username, $password, $options);    $j = 1;    $sql = "CALL view_eg208 (:bglpartno)";    $statement = $connection->prepare($sql);    $statement->bindParam(':bglpartno', $id);    $statement->execute();    $result = $statement->fetchAll();} catch (PDOException $error) {    echo $sql . "<br>" . $error->getMessage();}當(dāng)我更新所有值時(shí),它可以正常工作,但是當(dāng)單個(gè)值時(shí),它將第一個(gè)框的值更新到我選擇的那個(gè)框中。請(qǐng)幫我解決這個(gè)問題
查看完整描述

1 回答

?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

請(qǐng)像這樣輸入您的復(fù)選框,以便您獲得status正確的ck_id索引:


if ($result && $statement->rowCount() > 0) { 


    foreach ($result as $i => $row) { ?>


        <tr>


            <td>

                <input type="checkbox" id="ck_id[]"class="filled-in chk-col-blue" 

                name="ck_id[<?php echo $i ?>]" value="<?php echo escape ($row["ck_id"]);?>"/> 

            </td>   

            <td style="color:black"><?php echo escape 

                ($row["activity_name"]);?></td>

            <td>

                <div class="form-group has-danger" 

                style="margin-bottom: 0;">                   

                    <input type="text" id="status[]" name="status[<?php echo $i ?>]" 

                        maxlength="100" class="form-control" value="<? 

                        php echo escape ($row["status"]);?>" autocomplete="off" 

                        required="required" >                  

                    <div class="invalid-feedback">

                        Please provide a Inputs.

                    </div>

                </div>

            </td>    


        </tr>   


    <?php

    }

}

也嘗試使用foreach而不是for循環(huán):


    try {


        $connection = new PDO($dsn, $username, $password, $options);


        $status = $_POST['status'];

        $ck_id = $_POST['ck_id'];


        // for ($i = 0; $i < sizeof($ck_id); $i++) {

        foreach ($ck_id as $i => $value) {

            $sql = "UPDATE form_eg208 SET status=:status where ck_id IN (:ck_id)";

            $statement = $connection->prepare($sql);

            $statement->bindParam(':status', $status[$i]);

            $statement->bindParam(':ck_id', $ck_id[$i]);


            $statement->execute();

        }


    } catch (PDOException $error) {

        echo $sql . "<br>" . $error->getMessage();

    }


查看完整回答
反對(duì) 回復(fù) 2021-11-05
  • 1 回答
  • 0 關(guān)注
  • 146 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)