簡體   English   中英

更新數據庫表中所有行的1列

[英]Update 1 column of all rows in the database table

希望有人可以幫助我解決這個“ 簡單 ”的問題。

我在從mysql數據庫收集的表中有數據。 我希望用戶能夠將“ PRICE”列編輯為所有行,然后按“更新”按鈕,這會將數據發送到表並更新“ PRICE”列中的所有行。

為了我的一生,我無法更新數據庫。 我知道這一定是我所缺少的。 它必須很簡單,很可笑。

請幫忙?

if (isset($_POST['update']))
  {
  echo '<pre>';
  print_r($_POST);
  echo '</pre>';
  if (is_array($ID))
    {
    foreach($_POST['hidden'] AS $ID)
      {
      echo "ID is: " . $ID . "</br>";
      echo "Price is: " . $pricing . "</br>";
      $ID = mysqli_real_escape_string($conn, $_POST['hidden'][$ID]);
      $pricing = mysqli_real_escape_string($conn, $_POST['price'][$ID]);
      $updateQuery = 'UPDATE `bathroom_price` SET `price` ="' . $pricing . '" WHERE `ID`=' . $ID;
      mysqli_query($conn, $updateQuery) or die(mysql_error());
      }
    }
  }

?>
</head>
<?php
mysqli_select_db($conn, "table_name");
?>


<div class="row center-xs">
      <div style="margin-top:100px;" class="col-xs-12 col-sm-12 col-md-12 col-lg-8">
          <div class="box">
              <form method=POST>
                  <h1>Price List for Bathroom Form</h1>
                  <table>
                      <?
              $secondSQL = "SELECT question, question_ID, ID, form_ID, form_name FROM bathroom_price GROUP BY question_ID, form_name ORDER BY ID "; 
              $result1 = mysqli_query($conn, $secondSQL);
              while ($row = mysqli_fetch_assoc($result1))        
               { 
                  $question_ID = $row['question_ID'];
                  $question = $row['question'];
                  $formID = $row['form_ID'];
                  $form_name = $row['form_name'];
            ?>
                          <input type=hidden value="<? echo $question_ID ?>">
                          <tr class='questionHeading'>
                              <td colspan='3'>
                                  <h2><? echo $question ?></h2>
                                  <h3>Questions for the <? echo $form_name ?> Form</h3></td>
                          </tr>
                          <tr>
                              <th>Options:</th>
                              <th>Price:</th>
                              <th>Update:</th>
                          </tr>
                          <?  
                            $thirdSQL = "SELECT question_ID, options, price, ID FROM bathroom_price WHERE question_ID = $question_ID";
                            $replies = mysqli_query($conn, $thirdSQL);
                            while ($rows = mysqli_fetch_assoc($replies))
                             {

                                  $price = $rows['price'];
                                  $options = $rows['options'];
                                  $ID = $rows['ID'];

                              ?>
                              <input type=hidden name="hidden[]<?echo $ID ?>" value="<?echo $ID ?>" />
                              <input type=hidden value="<? echo $question_ID ?> " />
                              <tr>
                                  <td style='width:60%;'>
                                      <input readonly type=text value="<? echo $options ?>">
                                  </td>
                                  <td style='width:10%;'>
                                      <input type=text name="price[]<?echo $ID ?>" value="<?echo $price ?>">
                                  </td>
                              </tr>
                              <?}?>
                                  <?}?>
                  </table>
                  <div class="start-xs" style="margin: 0 0 50px 0;">
                      <button type=submit name="update" class="admin-style" value="Update Price Form">
                          <i class="fa fa-save"></i> Update Price Form
                      </button>
                  </div>
              </form>
          </div>
      </div>
  </div>
  </body>

  </html>
  <?php mysqli_close($conn);?>

也許這是一個問題:

<input type=hidden name="hidden[]<?echo $ID ?>" value="<?echo $ID ?>" />

您的輸入名稱是“ hidden [] 1”等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM