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

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

PHP - 將值插入到 HTML 表中每個(gè)用戶特定的數(shù)據(jù)庫(kù)中

PHP - 將值插入到 HTML 表中每個(gè)用戶特定的數(shù)據(jù)庫(kù)中

慕桂英546537 2023-10-10 14:57:08
我真的不知道最好的表達(dá)方式,所以我會(huì)盡力描述我想要實(shí)現(xiàn)的目標(biāo)。我有一個(gè)像這樣的表格內(nèi)的表格<form action="manager-match-report-run.php" method="post" autocomplete="off" name="registerForm">    <div class="table-responsive">        <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">            <thead>                <tr>                    <th>First Name</th>                    <th>Last Name</th>                    <th>Goals</th>                    <th>Assists</th>                    <th>Match Rating</th>                    <th hidden>playerId</th>                </tr>            </thead>            <tbody>                <?php                    $sql_players = "SELECT * FROM Player WHERE teamId = '$teamId' AND selected = '1'";                    $res_players = mysqli_query($conn, $sql_players);                    while($row_players = $res_players->fetch_assoc()) {                        echo "<tr>";                        echo "<td>" . $row_players["firstName"]. "</td>";                        echo "<td>" . $row_players["lastName"]. "</td>";                        echo "<td><div class='form-group'><input name='goals' class='form-control py-4' type='number'/></div></td>";                        echo "<td><div class='form-group'><input name='assists' class='form-control py-4' type='number'/></div></td>";                        echo "<td><div class='form-group'><input name='matchRating' class='form-control py-4' type='number' step='0.01' min='0' max='10'/></div></td>"                    ?>                    <td hidden><input name="playerId" value="<?php echo $row_players['playerId'];?>"></td>                    <?php echo "</tr>";                    }?>                </tbody>            </table>        </div>我正在尋找將數(shù)據(jù)插入 Player 表中正確行的正確方法。例如,更新球員表,使 Alison 有 5 個(gè)進(jìn)球、1 個(gè)助攻、8 個(gè)比賽評(píng)分,Ben 有 0 個(gè)進(jìn)球、1 個(gè)助攻、7 個(gè)比賽評(píng)分等。我假設(shè)我必須使用某種循環(huán),但到目前為止還沒(méi)有運(yùn)氣,所以任何幫助或建議都會(huì)很棒,謝謝:)
查看完整描述

1 回答

?
紫衣仙女

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

您的輸入都具有相同的名稱,因此只有最后一個(gè)值會(huì)發(fā)布到您的應(yīng)用程序。


為每個(gè)控件添加動(dòng)態(tài)名稱,例如name='matchRating',使用


$playerName = htmlentities($playername);

$inputname = sprintf("matchRating[%s]", $playerName);

printf("<input name=\"%s\" type=\"text\"/>", $inputname);

提交表單后,您將獲取數(shù)組中的數(shù)據(jù),您可以循環(huán)遍歷該數(shù)組以更新數(shù)據(jù)庫(kù)記錄:


$matchRatings = $_GET["matchRating"];

foreach ($matchRatings as $playerName => $rating) {

   // Update player rating in database

   // Important: Do not forget to guard against SQL injection!

   $sql = sprintf("update MYTABLE set MATCHRATING=%d where PLAYERNAME='%s'", $rating, $playerName);

}


查看完整回答
反對(duì) 回復(fù) 2023-10-10
  • 1 回答
  • 0 關(guān)注
  • 98 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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