启动时更新数据库按钮单击

ssgvzors  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(316)

我正在尝试向我的mysql数据库发送一个值,我对php/bootstrap编程非常陌生,我已经尝试了所有的方法,但是大多数指南都超出了我的理解范围。请引导我在正确的路径上,这样在按钮点击按钮将更新特定的数据库。
下面是按钮单击将要做的:在卸载按钮单击它将发送更新数据库,如
update activate=“no”from software where uid(or id)=“单击按钮的行的相同id”[我知道这个mysql查询是错误的]
这是我的密码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Control Panel</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="css/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="css/green.css" rel="stylesheet">
    <!-- Datatables -->
    <link href="css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="css/scroller.bootstrap.min.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-12 left_col">
          <div class="left_col scroll-view">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_content">
                    <table id="datatable-buttons" class="table table-striped table-bordered">
    <thead>
    <tr>
        <th>S/N</th>
        <th>Date</th>
        <th>IP Address</th>
        <th>UID</th>
        <th>Activation</th>
        <th>Command</th>
    </tr>
    </thead>        
    <tbody>

    <?php
    $count_rows = 0;
    include 'database_connection.php';
    $sql = "SELECT `date`, `ip`, `id`, `activate` FROM `software`";
    $result = $conn->query($sql);

    while ($row = mysqli_fetch_array($result)):
        $count_rows++;
        ?>
        <tr>
            <td><?php echo $count_rows ?></td>
            <td><?php echo $row['date']; ?></td>
            <td><?php echo $row['ip']; ?></td>
            <td><?php echo $row['id']; ?></td>
            <td><?php echo $row['activate']; ?> <td><button type="button" id="btn-uninstall" class="btn btn-danger btn-xs">Uninstall</button> <button type="button" id="btn-install" class="btn btn-success btn-xs">Install</button> <button type="button" id="btn-upgrade" class="btn btn-warning btn-xs">Upgrade</button></td>
        </tr>
    <?php endwhile; ?>
    </tbody>
</table>

    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="js/fastclick.js"></script>
    <!-- NProgress -->
    <script src="js/nprogress.js"></script>
    <!-- iCheck -->
    <script src="js/icheck.min.js"></script>
    <!-- Datatables -->
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap.min.js"></script>
    <script src="js/dataTables.buttons.min.js"></script>
    <script src="js/buttons.bootstrap.min.js"></script>
    <script src="js/buttons.flash.min.js"></script>
    <script src="js/buttons.html5.min.js"></script>
    <script src="js/buttons.print.min.js"></script>
    <script src="js/dataTables.fixedHeader.min.js"></script>
    <script src="js/dataTables.keyTable.min.js"></script>
    <script src="js/dataTables.responsive.min.js"></script>
    <script src="js/responsive.bootstrap.js"></script>
    <script src="js/dataTables.scroller.min.js"></script>
    <script src="js/jszip.min.js"></script>
    <script src="js/pdfmake.min.js"></script>
    <script src="js/vfs_fonts.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="js/custom.min.js"></script>

  </body>
</html>

以下是页面截图:https://image.ibb.co/etoeaz/capture.png

wtlkbnrh

wtlkbnrh1#

如果您希望它立即发生,那么使用ajax将请求发送到php服务器,请参阅https://www.w3schools.com/php/php_ajax_database.asp 更多信息。
如果你想它与重定向然后使用

$conn = new mysqli("DBservername", "DBusername", "DBpassword", "DBname");
if ($conn->connect_errno) {
    $errormsg = ("Database Connection failed: " . $conn->connect_error );
    return $errormsg;
}
$res=mysqli_query($conn, "SELECT * FROM 'table' WHERE 'something'");
$row=$res->fetch_array();
$count = mysqli_num_rows($res); // if fetch correct it returns must be 1 row
mysqli_close($conn);
if( $count == 1 ) etc

发送查询、更新、删除等。

$sql = "DELETE FROM 'table' WHERE 'something';
mysqli_query($conn,$sql);

粗糙和糟糕的php代码,但应该工作。
在我理解了您的实际要求之后进行编辑:当呈现来自数据库的结果时,锚定每个按钮以重定向到页面/update/{rowid}或/update.php?id={rowid}
并在该链接中使用条件等执行查询。

bn31dyow

bn31dyow2#

您可以通过此代码向服务器发送请求。

$con = new mysqli_connect("servername", "username", "password", "name");
    if(!$con)
    {
       die("DB CONNECTION ERROR");

    }
    $result=mysqli_query($con, "SELECT * FROM 'table' WHERE 'something'");
    $row=$result->fetch_array();
    $count = mysqli_num_rows($result); 
    mysqli_close($con);
    if( $count == 1 )

相关问题