如何将DATA转换为输入字段-PHP

我试图在这里创建表,可以在其中从mysql提取所有数据.

如何将DATA转换为输入字段-PHP

我在字段上添加了两个额外的按钮,以编辑和删除所选的特定项目.

现在,我不确定如何将文本转换为输入字段(每当我单击“编辑”按钮时),然后编辑信息并使编辑按钮变为保存状态(在编辑模式下,显示输入内容) )按钮,以便进行更改/更新.我也不确定如何获取ID,因此可以更新该特定字段.

到目前为止,这是我的代码:

  function readData(){
    global $connection;

    $query = "SELECT * FROM users";

    $result = mysqli_query($connection, $query);

   if(!$result) {
       die('Query FAILED' . mysqli_error());
    }

     while($row = mysqli_fetch_assoc($result)){ 
      $id = $row['id'];
      $username = $row['username'];
      $password = $row['password'];

      echo '<tr>';
      echo "<td>$id</td>";
      echo "<td>$username</td>";
      echo "<td>$password</td>";
      echo "<td><button id='edit' name='edit'>EDIT</button></td>";
      echo "<td><button id='delete' name='delete'>DELETE</button></td>";
      echo '</tr>';
     }
  }

  function editDate(){
    global $connection;

    $query = "UPDATE users SET ";
    $query .= "username = '$username', ";
    $query .= "password = '$password' ";
    $query .= "WHERE id='$id'";

    $result = mysqli_query($connection, $query);
    if(!$result){
      die('QUERY FAILED' . mysqli_error($connection));
    }
  }

这是我的主文件…

<?php 
   include 'functions.php';
?>

<?php include 'includes/header.php' ?>


<table style="width: 200px;" border="1">
  <tr>
    <th>ID</th>
    <th>USERNAME</th> 
    <th>PASSWORD</th>
    <th>EDIT</th>
    <th>DELETE</th>
  </tr>
  <tr>
    <?php readData(); ?>
  </tr>
</table>


<?php include 'includes/footer.php' ?>

知道如何实施吗?

解决方法:

单击任何行的数据时,必须调用onclick jquery事件.
我认为它将对您有很大帮助. https://codewithmark.com/easily-edit-html-table-rows-or-cells-with-jquery

也拨弄代码:-http://jsfiddle.net/9KEGd/

享受代码

上一篇:cobbler部署


下一篇:PHP-mysqli_fetch_assoc()发出警告,要求使用mysqli_result,但给定对象