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

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

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

      1. 如何在单击按钮时执行mysql

        时间:2023-12-01
        <tfoot id='bwvLY'></tfoot>
          <i id='bwvLY'><tr id='bwvLY'><dt id='bwvLY'><q id='bwvLY'><span id='bwvLY'><b id='bwvLY'><form id='bwvLY'><ins id='bwvLY'></ins><ul id='bwvLY'></ul><sub id='bwvLY'></sub></form><legend id='bwvLY'></legend><bdo id='bwvLY'><pre id='bwvLY'><center id='bwvLY'></center></pre></bdo></b><th id='bwvLY'></th></span></q></dt></tr></i><div id='bwvLY'><tfoot id='bwvLY'></tfoot><dl id='bwvLY'><fieldset id='bwvLY'></fieldset></dl></div>
            1. <small id='bwvLY'></small><noframes id='bwvLY'>

              <legend id='bwvLY'><style id='bwvLY'><dir id='bwvLY'><q id='bwvLY'></q></dir></style></legend>
                <tbody id='bwvLY'></tbody>
                <bdo id='bwvLY'></bdo><ul id='bwvLY'></ul>
                  本文介绍了如何在单击按钮时执行mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  PHP:
                  单击按钮时如何执行 SQL?我会使用 JavaScript onClick() 函数还是其他方式?我正在尝试在循环中执行此操作,并且仅在单击按钮的行上执行 sql ...谢谢!

                  PHP:
                  How would I execute SQL when a button is clicked? Would I do it with the JavaScript onClick() function, or some other way? I am trying to do this inside of a loop, and only execute the sql on the row that the button is clicked on... Thanks!

                  @PHPnoOb 的代码可提供帮助:好的,所以现在我已经整理好了所有这些,但是当单击按钮时,它会为每一行执行一次……而不仅仅是单击按钮的那一行!我只想查询单击按钮的行...我的代码:

                  Code for @PHPnoOb to help: Okay, so now I have all of that sorted out, but when the button is clicked it executes once for each row... not just once for the row the button was clicked on! I only want the row that the button was clicked on to be queried... my code:

                  while($row = mysqli_fetch_array($result)) {
                  
                  //FAULTY CODE!!! EXECUTES ONCE FOR EACH ROW!
                  //I WANT IT TO ONLY EXECUTE FOR THE ROW THE
                  //BUTTON WAS CLICKED ON
                  
                  if(isset($_POST['delete'])){
                  echo "You clicked on: ".$row['subject'];
                  //eventually i will have sql query up here
                  }
                  //echo all the results into a table... messy
                  echo"
                  
                  <tr><td><div align='center'><font color='grey'>".$row['date']."</font></div></td><td><div align='center'> ".$row['sender']."</div></td><td><div align='center'> ".$row['subject']."</div></td><td><div align='center'><input type='button' value='open' onClick='window.alert("On ".$row['date']." ".$row['sender']." wrote:\n".$row['message']."")'/></div></td><td><div align='center'><form  method='post'><input type='submit' value='delete' name='delete'/></form></div></td></tr>
                  
                  ";
                  
                  }
                  
                  echo '</table>'; //ends the table.
                  

                  推荐答案

                  您可以执行类似的操作来保存输入/提交 btn 中的值.

                  You can do something like this to save a value from an input/submit btn.

                  <!-- your html form -->
                  <form action="POST">
                      <input type='text' name='username' />
                      <input type='text' value='submit' />
                  </form>
                  
                  
                  
                  <?php 
                  
                  // your php code
                  
                  if($_POST && isset($_POST['username'])){
                  
                      $db = new PDO('......'); // enter your db details
                  
                      $stmt = $db->prepare("INSERT INTO table (username) VALUES (?)");
                      $result = $stmt->execute(array($_POST['username']);
                  
                      echo $result->rowCount() ? 'Username saved in db' : 'Unknown error occured'; 
                  
                  }
                  

                  这篇关于如何在单击按钮时执行mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 onClick HTML 事件之后调用 PHP 函数 下一篇:识别相似图像的好方法?

                  相关文章

                    <bdo id='vFa0U'></bdo><ul id='vFa0U'></ul>
                • <legend id='vFa0U'><style id='vFa0U'><dir id='vFa0U'><q id='vFa0U'></q></dir></style></legend>

                • <small id='vFa0U'></small><noframes id='vFa0U'>

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