久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <tfoot id='HXuAU'></tfoot><legend id='HXuAU'><style id='HXuAU'><dir id='HXuAU'><q id='HXuAU'></q></dir></style></legend>

      <small id='HXuAU'></small><noframes id='HXuAU'>

    2. <i id='HXuAU'><tr id='HXuAU'><dt id='HXuAU'><q id='HXuAU'><span id='HXuAU'><b id='HXuAU'><form id='HXuAU'><ins id='HXuAU'></ins><ul id='HXuAU'></ul><sub id='HXuAU'></sub></form><legend id='HXuAU'></legend><bdo id='HXuAU'><pre id='HXuAU'><center id='HXuAU'></center></pre></bdo></b><th id='HXuAU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HXuAU'><tfoot id='HXuAU'></tfoot><dl id='HXuAU'><fieldset id='HXuAU'></fieldset></dl></div>
          <bdo id='HXuAU'></bdo><ul id='HXuAU'></ul>

        使用 foreach 循環插入多個字段

        insert multiple fields using foreach loop(使用 foreach 循環插入多個字段)
        1. <tfoot id='yJgeW'></tfoot>
            <tbody id='yJgeW'></tbody>

          <small id='yJgeW'></small><noframes id='yJgeW'>

                <i id='yJgeW'><tr id='yJgeW'><dt id='yJgeW'><q id='yJgeW'><span id='yJgeW'><b id='yJgeW'><form id='yJgeW'><ins id='yJgeW'></ins><ul id='yJgeW'></ul><sub id='yJgeW'></sub></form><legend id='yJgeW'></legend><bdo id='yJgeW'><pre id='yJgeW'><center id='yJgeW'></center></pre></bdo></b><th id='yJgeW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='yJgeW'><tfoot id='yJgeW'></tfoot><dl id='yJgeW'><fieldset id='yJgeW'></fieldset></dl></div>
                  <bdo id='yJgeW'></bdo><ul id='yJgeW'></ul>

                • <legend id='yJgeW'><style id='yJgeW'><dir id='yJgeW'><q id='yJgeW'></q></dir></style></legend>
                  本文介紹了使用 foreach 循環插入多個字段的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  當我想在一個表中插入多個字段時遇到問題.

                  I have a problem when I want to insert multiple fields into one table.

                  這是我的表格:

                  <h1>Add user</h1>
                   <form method="post" action="index.php">
                  
                   <table>
                      <thead>
                          <th>Name</th>
                          <th>Age</th>
                      </thead>
                  
                      <tr>
                          <td><input name="name[]" type="text" /></td>
                          <td><input name="age[]" type="text" /></td>
                      </tr>
                  
                      <tr>
                          <td><input name="name[]" type="text" /></td>
                          <td><input name="age[]" type="text" /></td>
                      </tr>
                  
                      <tr>
                          <td><input name="name[]" type="text" /></td>
                          <td><input name="age[]" type="text" /></td>
                      </tr>
                  </table>
                  
                   <input type="submit" name="submit" value="Submit" />
                   </form>
                  

                  這是提交代碼:

                  if (isset($_POST['submit'])) {
                  
                      foreach ($_POST as $val) {
                          $name = $val['name'];
                          $age = $val['age'];
                  
                          mysql_query("INSERT INTO users (name, age) VALUES ('$name', '$age')");
                      } 
                  }
                  

                  查詢插入到數據庫中,但不是我輸入的值.

                  The query inserts into the database, but not the values that I've entered.

                  有人可以幫我嗎?

                  推薦答案

                  您正在對 $_POST 而不是 name/age 數組執行 foreach.您應該像這樣對 name 或 age 數組執行 foreach:

                  You are doing a foreach on $_POST rather than on the name/age arrays. You should be doing foreach on name or age array like this:

                  if (
                     !empty($_POST['name']) && !empty($_POST['age']) &&
                     is_array($_POST['name']) && is_array($_POST['age']) &&
                     count($_POST['name']) === count($_POST['age'])
                  ) {
                      $name_array = $_POST['name'];
                      $age_array = $_POST['age'];
                      for ($i = 0; $i < count($name_array); $i++) {
                  
                          $name = mysql_real_escape_string($name_array[$i]);
                          $age = mysql_real_escape_string($age_array[$i]);
                  
                          mysql_query("INSERT INTO users (name, age) VALUES ('$name', '$age')");
                      } 
                  }
                  

                  我還注意到您目前很容易受到 SQL 注入的影響,因此我添加了為名稱/年齡轉義字符串的步驟.

                  I would also note that you are currently susceptible to SQL injection so I added the step of escaping your strings for name/age.

                  我還強烈建議簡單地將單個批量插入到數據庫中,而不是單獨插入每條記錄(我將把它留給您來實現).從性能的角度來看,這種方法幾乎總是更可取的.

                  I would also highly suggest simply making a single bulk insert into the DB instead of an insert of each record individually (I will leave that up to you to implement). This approach is almost always preferable from a performance standpoint.

                  最后,您真的不應該使用 mysql_* 函數,因為它們已被棄用.考慮改用mysqli或PDO.

                  Finally, you REALLY should not be using mysql_* functions as they are deprecated. Consider changing to mysqli or PDO.

                  這篇關于使用 foreach 循環插入多個字段的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

                      • <legend id='uFSyx'><style id='uFSyx'><dir id='uFSyx'><q id='uFSyx'></q></dir></style></legend>
                          <tbody id='uFSyx'></tbody>

                        <small id='uFSyx'></small><noframes id='uFSyx'>

                          <bdo id='uFSyx'></bdo><ul id='uFSyx'></ul>
                          <tfoot id='uFSyx'></tfoot>
                          <i id='uFSyx'><tr id='uFSyx'><dt id='uFSyx'><q id='uFSyx'><span id='uFSyx'><b id='uFSyx'><form id='uFSyx'><ins id='uFSyx'></ins><ul id='uFSyx'></ul><sub id='uFSyx'></sub></form><legend id='uFSyx'></legend><bdo id='uFSyx'><pre id='uFSyx'><center id='uFSyx'></center></pre></bdo></b><th id='uFSyx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uFSyx'><tfoot id='uFSyx'></tfoot><dl id='uFSyx'><fieldset id='uFSyx'></fieldset></dl></div>

                            主站蜘蛛池模板: 日日爱av | 色天天综合 | 九色在线观看 | 色欧美片视频在线观看 | 欧美aⅴ片| 99热精品在线观看 | 久久久久久久久久久一区二区 | 亚洲一区二区三区在线播放 | 天天摸天天干 | 欧美日韩在线观看一区二区三区 | 中文字幕欧美一区 | 91色啪 | 午夜寂寞福利视频 | 精品一区二区久久久久久久网站 | 国产在线麻豆精品入口 | 精品96久久久久久中文字幕无 | 精品一二区 | 久久剧场 | 精品一区二区三区在线观看国产 | 日韩精品一区二区三区 | 国产在线a| 日韩精品一区二区三区在线观看 | 成人在线视频网站 | 成人免费观看网站 | 亚洲视频中文 | 青青草在线视频免费观看 | 91精品国产色综合久久不卡98 | 国产精品久久久久免费 | www.亚洲精品 | 精品国产一区二区在线 | 精品国产一区二区三区日日嗨 | 免费看国产片在线观看 | 欧美成人手机视频 | 日本国产高清 | 玖草资源 | 日日日日日日bbbbb视频 | 久久99精品久久久久久狂牛 | 中文字幕免费在线 | 久久亚洲一区二区三区四区 | 一区二区三区在线 | 亚洲视频在线免费 |