久久久久久久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在线视| 一区二区三区四区免费视频 | 91精品国产综合久久久久久丝袜 | 欧美在线视频一区 | 亚洲精品永久免费 | 国产欧美精品 | 一区二区在线不卡 | 成人免费av在线 | 成人片免费看 | 国产99久久久国产精品下药 | 婷婷狠狠 | 日韩www| 免费观看一级特黄欧美大片 | 懂色av蜜桃av | 91精品久久久久久久99 | 区一区二区三在线观看 | 国产日韩一区二区三免费高清 | 国产性生活一级片 | 91视视频在线观看入口直接观看 | av在线免费观看网址 | 亚洲视频在线播放 | 亚州中文 | 免费观看日韩精品 | 国内精品久久影院 | 亚洲精选一区二区 | 国产精品片 | av先锋资源 | 日韩国产欧美视频 | 天堂资源最新在线 | 日日操日日干 | 亚洲欧美日韩系列 | 国产福利91精品一区二区三区 | 久久人人国产 | 久久亚洲国产精品 | 欧美美乳| 国产精品久久久久久久久久久久午夜片 | 亚洲一区高清 | 日韩一二区 | 欧美日韩精选 | 美女日皮网站 |