简体   繁体   English

更新数据库表中所有行的1列

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

Hopefully someone can help me with this " easy " question. 希望有人可以帮助我解决这个“ 简单 ”的问题。

I have data in a table that has been gathered from a mysql database. 我在从mysql数据库收集的表中有数据。 I want the user to be able to edit the "PRICE" column to any and all rows, then press the update button which will send the data to the table and update all the rows in the "PRICE" column. 我希望用户能够将“ PRICE”列编辑为所有行,然后按“更新”按钮,这会将数据发送到表并更新“ PRICE”列中的所有行。

For the life of me I can't get the database to update. 为了我的一生,我无法更新数据库。 I know it has to be something that I'm missing. 我知道这一定是我所缺少的。 And it has to be something so easy it's laughable. 它必须很简单,很可笑。

Please help? 请帮忙?

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);?>

Maybe this is a problem: 也许这是一个问题:

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

Your input name is "hidden[]1" etc. 您的输入名称是“ hidden [] 1”等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM