• <bdo id='soVks'></bdo><ul id='soVks'></ul>
      1. <i id='soVks'><tr id='soVks'><dt id='soVks'><q id='soVks'><span id='soVks'><b id='soVks'><form id='soVks'><ins id='soVks'></ins><ul id='soVks'></ul><sub id='soVks'></sub></form><legend id='soVks'></legend><bdo id='soVks'><pre id='soVks'><center id='soVks'></center></pre></bdo></b><th id='soVks'></th></span></q></dt></tr></i><div id='soVks'><tfoot id='soVks'></tfoot><dl id='soVks'><fieldset id='soVks'></fieldset></dl></div>
      2. <tfoot id='soVks'></tfoot>
        <legend id='soVks'><style id='soVks'><dir id='soVks'><q id='soVks'></q></dir></style></legend>

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

        单击按钮更新信息表

        时间:2024-08-23
            • <bdo id='OIyy6'></bdo><ul id='OIyy6'></ul>

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

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

                1. <i id='OIyy6'><tr id='OIyy6'><dt id='OIyy6'><q id='OIyy6'><span id='OIyy6'><b id='OIyy6'><form id='OIyy6'><ins id='OIyy6'></ins><ul id='OIyy6'></ul><sub id='OIyy6'></sub></form><legend id='OIyy6'></legend><bdo id='OIyy6'><pre id='OIyy6'><center id='OIyy6'></center></pre></bdo></b><th id='OIyy6'></th></span></q></dt></tr></i><div id='OIyy6'><tfoot id='OIyy6'></tfoot><dl id='OIyy6'><fieldset id='OIyy6'></fieldset></dl></div>

                  本文介绍了单击按钮更新信息表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个表格,可以从数据库中选择信息并显示它,我想知道是否有人可以提供代码让我通过单击按钮更新列?

                  I have a table which will select information from a database and display it, I'm wondering if anyone can provide a code for me to update a column on the click of a button?

                  示例表:(Access=Boolean)

                  Example Table: (Access=Boolean)

                  ID   -   Name   -   Access
                  ---------------------------
                  1   -   John    -    1
                  ---------------------------
                  2   -   Ben     -    1
                  ---------------------------
                  3   -   Terry   -    0
                  ---------------------------
                  

                  我的现有按钮基于引导程序,

                  My exisiting button is based on bootstrap,

                      <button type="button" id="passed" class="btn btn-success btn-flat"><i class="fa fa-check"></i></button>
                      <button type="button" id="insufficient" class="btn btn-danger btn-flat"><i class="fa fa-times"></i></button>
                  

                  我希望有这样的东西,ONCLICK button1 运行 $Allowed SQLONCLICK 按钮2 运行 $NotAllowed SQL

                  I was hoping for something like this, ONCLICK button1 Run $Allowed SQL ONCLICK button2 Run $NotAllowed SQL

                  $allowed = mysqli_query($conn," UPDATE users SET Access = "1" WHERE id = '27' ");     
                  $notallowed = mysqli_query($conn," UPDATE users SET Access = "0" WHERE id = '453' ");
                  

                  推荐答案

                  您可以使用带有 post 方法的表单和带有命名属性的提交类型的按钮,并在条件语句中使用它们.

                  You can use a form with a post method and a submit type of buttons with named attributes and use those in a conditional statement.

                  即:

                  旁注:我删除了转义的引号,因为我不确定它们是否已经设置在回声中.

                  Sidenote: I removed the escaped quotes, as I was not sure if those were already set inside an echo.

                  HTML 表单:

                  <form method="post" action="handler.php">
                  
                      <button type="submit" name="passed" id="passed" class="btn btn-success btn-flat"><i class="fa fa-check"></i></button>
                      <button type="submit" name="insufficient" id="insufficient" class="btn btn-danger btn-flat"><i class="fa fa-times"></i></button>
                  
                  </form>
                  

                  PHP:

                  <?php 
                  
                  // db connection
                  
                  if(isset($_POST['passed'])){
                  
                      $allowed = mysqli_query($conn," UPDATE users SET Access = "1" WHERE id = '27' ");
                  
                  }
                  
                  if(isset($_POST['insufficient'])){
                  
                      $notallowed = mysqli_query($conn," UPDATE users SET Access = "0" WHERE id = '453' ");
                  
                  }
                  

                  • 如果这在任何给定点有任何用户交互,请小心.

                    • Be careful if this has any user interaction at any given point.

                      使用 准备好的语句,或 带有准备好的语句的 PDO它们更安全.

                      脚注:

                      运行 UPDATE 查询时,最好使用 mysqli_affected_rows() 以保证绝对真实性.

                      When running an UPDATE query, it's best to use mysqli_affected_rows() for absolute truthness.

                      • http://php.net/manual/en/mysqli.affected-rows.php

                      否则,您可能会得到误报.

                      Otherwise, you may get a false positive.

                      这篇关于单击按钮更新信息表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 MySQL UPDATE (PHP/MySQL) 中使用变量 下一篇:如何配置 PHP 发送电子邮件?

                  相关文章

                  <i id='tbNVa'><tr id='tbNVa'><dt id='tbNVa'><q id='tbNVa'><span id='tbNVa'><b id='tbNVa'><form id='tbNVa'><ins id='tbNVa'></ins><ul id='tbNVa'></ul><sub id='tbNVa'></sub></form><legend id='tbNVa'></legend><bdo id='tbNVa'><pre id='tbNVa'><center id='tbNVa'></center></pre></bdo></b><th id='tbNVa'></th></span></q></dt></tr></i><div id='tbNVa'><tfoot id='tbNVa'></tfoot><dl id='tbNVa'><fieldset id='tbNVa'></fieldset></dl></div>
                2. <small id='tbNVa'></small><noframes id='tbNVa'>

                    <legend id='tbNVa'><style id='tbNVa'><dir id='tbNVa'><q id='tbNVa'></q></dir></style></legend>
                      <bdo id='tbNVa'></bdo><ul id='tbNVa'></ul>
                    1. <tfoot id='tbNVa'></tfoot>