Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在HTML表中创建一个按钮来更新数据库中的信息_Php_Html_Button_Mysqli - Fatal编程技术网

Php 如何在HTML表中创建一个按钮来更新数据库中的信息

Php 如何在HTML表中创建一个按钮来更新数据库中的信息,php,html,button,mysqli,Php,Html,Button,Mysqli,我对编码一无所知。尽管如此,我希望你能帮助我解决这个问题。 我使用PHP和Mysqli在html表中填充信息。我在其中一列中添加了一个按钮。我想单击按钮并在数据库中更新表中该行的信息。 用户赚取佣金,因此,通过单击按钮,我希望将pay列中的金额移动到pay列并更新数据库 当我点击按钮时,我会收到一条成功消息,上面说付款已成功处理,但数据库中没有任何更改! 提前感谢您提供的任何帮助。 这是我的密码: <html> <body> <div class="form"

我对编码一无所知。尽管如此,我希望你能帮助我解决这个问题。 我使用PHP和Mysqli在html表中填充信息。我在其中一列中添加了一个按钮。我想单击按钮并在数据库中更新表中该行的信息。 用户赚取佣金,因此,通过单击按钮,我希望将pay列中的金额移动到pay列并更新数据库

当我点击按钮时,我会收到一条成功消息,上面说付款已成功处理,但数据库中没有任何更改! 提前感谢您提供的任何帮助。 这是我的密码:

 <html>
 <body>
 <div class="form">

 <h2>View Records</h2>

 <table  width='100%'> 
 <thead>
 <tr>
 <th><strong>user ID</strong></th>
 <th><strong>Fist Name</strong></th>
 <th><strong>Last Name</strong></th>
 <th><strong>pay commission</strong></th>
 <th><strong>Paid</strong></th>
 <th><strong>Pay Commission</strong></th>
 <th><strong>Delete</strong></th>
 </tr>
 </thead>
 <tbody>
    <?php
     $count=1;
     include "db.php";
     $sql = "SELECT  * FROM users  ";
     $result = $conn-> query($sql);
       if($result -> num_rows > 0){
     while ($row = $result-> fetch_assoc()) { ?>

   <td align="center"><?php echo $row["id"]; ?></td>
   <td align="center"><?php echo $row["first_name"]; ?></td>
   <td align="center"><?php echo $row["last_name"]; ?></td>
   <td align="center"><?php echo $row["pay"]; ?></td>
   <td align="center"><?php echo $row["paid"]; ?></td>
   <td align="center">
   <div class="input-group">
   <form class="reset-form" action="members.php" method="post" >
   <div class="input-group">
   <button type="submit" class="button_1" name="pay-commission">Pay Commission</button></div></form>

   </td>
   <td align="center">
   <a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a>
   </td>
   </tr>
     <?php
  }

        // process commission*******
        if(isset($_POST["pay-commission"])){

       $id=$row['id'];
       $pay=$row['pay'];
       $paid=$row['last_paid']; 

      //date and time of transaction
          $trn_date = date("Y-m-d H:i:s");

    require('db.php');
    $ins_query="update users  last_paid='$pay' trm_date='$trn_date'  where id= '$id'";

            mysqli_query($conn,$ins_query);

         if($ins_query){
        echo "<p class= 'success'> Payment Processed Successfully <p>"; 
          }else{
       echo"<p class= 'error'>something went wrong!!</p>";
          }
            }
           }

      ?>
</tbody>
</table>
</div>
</body>
</html>

让它工作,除了它更新所有用户点击任何按钮在支付佣金列。一次点击处理所有佣金可能不是一件坏事。 也许我可以移动表格下方的按钮,只需单击一下即可更新所有用户。所有这些代码都位于名为members.php的页面上

 <html>
 <head></head> <header></header>

  <body>
  //table structure

<div class="form">
<h2>View Records</h2>

<table  width='100%'> 
<thead>
<tr>
<th><strong>user ID</strong></th>
<th><strong>Fist Name</strong></th>
<th><strong>Last Name</strong></th>
<th><strong>pay commission</strong></th>
<th><strong>Paid</strong></th>
<th><strong>Pay Commission</strong></th>
    <th><strong>Delete</strong></th>
</tr>
</thead>
<tbody>

     //populate table with user data

<?php
$count=1;
    include "db.php";
$sql = "SELECT  * FROM users  ";
$result = $conn-> query($sql);
if($result -> num_rows > 0){
    while ($row = $result-> fetch_assoc()) { ?>

    <td align="center"><?php echo $row["id"]; ?></td>
    <td align="center"><?php echo $row["first_name"]; ?></td>
    <td align="center"><?php echo $row["last_name"]; ?></td>
    <td align="center"><?php echo $row["pay"]; ?></td>
    <td align="center"><?php echo $row["last_paid"]; ?></td>
    <td align="center">
    <div class="input-group">
    <form  action="members.php" method="post" >
    <div class="input-group">
    <button type="submit" class="button_1" name="pay-commission">Pay           commission</button></div></form>

    </td>
    <td align="center">
    <a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a>
    </td>
    </tr>
    <?php


// process commission*******
    if(isset($_POST["pay-commission"])){

$id=$row['id'];
$pay=$row['pay'];
$paid=$row['last_paid'];

    //set the date and time of transaction

$trn_date = date('Y-m-d');




$conn->query("UPDATE users SET  last_paid='$pay'  WHERE id= '$id'");
$conn->query("UPDATE users SET  pay=0.00 WHERE id= '$id'");
$conn->query("UPDATE users SET  trn_date='$trn_date' WHERE id= '$id'");


if($conn){
    //refresh the page to see changes
header ('Location: members.php');
echo '<p class="success"> A Payment of $$pay Processed Successfully for member ID     $id</p>';
    }else{
        echo '<p class="error">Something went wrong! </p>';
    }


   }
  }
 }  

$conn->close();
  ?>    

 </tbody>
 </table>
 </div>




 </body>
 </html>

$ins_query=update users SET last_paid='$pay'trm_date='$trn_date',其中id='$id';您忘了在查询中添加集合,所以您没有在表单中发送任何数据,在这里您可以添加一些隐藏的输入框,并从数据库中设置这些值。支付佣金您的表单为空$id=$row['id']$pay=$row['pay']$已付=$row[“上次已付”];在ifisset$\u POST[支付佣金]中没有任何意义。1实际上,您不知道基于此点选了哪一行,当然也不想更新所有行。2您正在更新行,但仅使用与已存在的数据完全相同的数据。正如MUFAzmi所提示的,您需要表行中的一些输入字段,而不仅仅是静态数据,以及b,以便在提交时通过$\u POST捕获这些输入字段的值。发布的代码包含太多语法错误。在评论中发布的内容不止这些。