使用复选框删除多行

时间:2019-11-29 04:04:12

标签: php mysql

我有此代码

2019-11-29T11:39:33.207+0900 I CONTROL  [main] ***** SERVER RESTARTED *****
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] MongoDB starting : pid=1895 port=27018 dbpath=/mongo/data 64-bit host=staging-sop-mongo-sh00rs2
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] db version v3.6.12
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] git version: c2b9acad0248ca06b14ef1640734b5d0595b55f1
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] allocator: tcmalloc
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] modules: none
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] build environment:
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten]     distmod: rhel62
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten]     distarch: x86_64
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten]     target_arch: x86_64
2019-11-29T11:39:33.221+0900 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0", port: 27018 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, replication: { replSetName: "sh00" }, sharding: { clusterRole: "shardsvr" }, storage: { dbPath: "/mongo/data", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongo/mongod.log" } }
2019-11-29T11:39:33.222+0900 I -        [initandlisten] Detected data files in /mongo/data created by the 'mmapv1' storage engine, so setting the active storage engine to 'mmapv1'.
2019-11-29T11:39:33.254+0900 I JOURNAL  [initandlisten] journal dir=/mongo/data/journal
2019-11-29T11:39:33.254+0900 I JOURNAL  [initandlisten] recover begin
2019-11-29T11:39:33.254+0900 I JOURNAL  [initandlisten] info no lsn file in journal/ directory
2019-11-29T11:39:33.254+0900 I JOURNAL  [initandlisten] recover lsn: 0
2019-11-29T11:39:33.254+0900 I JOURNAL  [initandlisten] recover /mongo/data/journal/j._0
2019-11-29T11:39:33.255+0900 I JOURNAL  [initandlisten] recover applying initial journal section with sequence number 105
2019-11-29T11:39:33.266+0900 I JOURNAL  [initandlisten] recover cleaning up
2019-11-29T11:39:33.266+0900 I JOURNAL  [initandlisten] removeJournalFiles
2019-11-29T11:39:33.266+0900 I JOURNAL  [initandlisten] old journal file will be removed: /mongo/data/journal/j._0
2019-11-29T11:39:33.297+0900 I JOURNAL  [initandlisten] recover done
2019-11-29T11:39:33.297+0900 I JOURNAL  [initandlisten] preallocating a journal file /mongo/data/journal/prealloc.0
2019-11-29T11:39:36.021+0900 I -        [initandlisten]   File Preallocator Progress: 178257920/1073741824 16%
2019-11-29T11:39:39.135+0900 I -        [initandlisten]   File Preallocator Progress: 293601280/1073741824 27%
2019-11-29T11:39:42.024+0900 I -        [initandlisten]   File Preallocator Progress: 408944640/1073741824 38%
2019-11-29T11:39:45.254+0900 I -        [initandlisten]   File Preallocator Progress: 545259520/1073741824 50%
2019-11-29T11:39:48.068+0900 I -        [initandlisten]   File Preallocator Progress: 660602880/1073741824 61%
2019-11-29T11:39:51.392+0900 I -        [initandlisten]   File Preallocator Progress: 786432000/1073741824 73%
2019-11-29T11:39:54.145+0900 I -        [initandlisten]   File Preallocator Progress: 901775360/1073741824 83%
2019-11-29T11:39:57.285+0900 I -        [initandlisten]   File Preallocator Progress: 1027604480/1073741824 95%
2019-11-29T11:40:00.856+0900 I JOURNAL  [durability] Durability thread started
2019-11-29T11:40:00.856+0900 I JOURNAL  [journal writer] Journal writer thread started
2019-11-29T11:40:00.862+0900 I CONTROL  [initandlisten]
2019-11-29T11:40:00.862+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-11-29T11:40:00.862+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-11-29T11:40:00.862+0900 I CONTROL  [initandlisten]
2019-11-29T11:40:00.864+0900 I CONTROL  [initandlisten]
2019-11-29T11:40:00.864+0900 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 65536 files. Number of processes should be at least 32768 : 0.5 times number of files.
2019-11-29T11:40:01.054+0900 I SHARDING [initandlisten] initializing sharding state with: { _id: "shardIdentity", configsvrConnectionString: "cfg/172.18.102.12:27019,172.18.102.13:27019,172.18.102.14:27019", shardName: "sh00", clusterId: ObjectId('5db7f79ff59febd48e8fecce') }
2019-11-29T11:40:01.054+0900 I SHARDING [initandlisten] first cluster operation detected, adding sharding hook to enable versioning and authentication to remote servers
2019-11-29T11:40:01.065+0900 I NETWORK  [initandlisten] Starting new replica set monitor for cfg/172.18.102.12:27019,172.18.102.13:27019,172.18.102.14:27019
2019-11-29T11:40:01.071+0900 I SHARDING [initandlisten] initialized sharding components for secondary node.
2019-11-29T11:40:01.072+0900 I SHARDING [thread1] creating distributed lock ping thread for process staging-sop-mongo-sh00rs2:27018:1574995201:-3977297405042744167 (sleeping for 30000ms)
2019-11-29T11:40:01.076+0900 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to 172.18.102.14:27019 (1 connections now open to 172.18.102.14:27019 with a 5 second timeout)
2019-11-29T11:40:01.076+0900 I NETWORK  [initandlisten] Successfully connected to 172.18.102.13:27019 (1 connections now open to 172.18.102.13:27019 with a 5 second timeout)
2019-11-29T11:40:01.077+0900 I NETWORK  [shard registry reload] Successfully connected to 172.18.102.12:27019 (1 connections now open to 172.18.102.12:27019 with a 5 second timeout)
2019-11-29T11:40:01.080+0900 I ASIO     [NetworkInterfaceASIO-ShardRegistry-0] Connecting to 172.18.102.13:27019
2019-11-29T11:40:01.081+0900 I ASIO     [NetworkInterfaceASIO-ShardRegistry-0] Connecting to 172.18.102.12:27019
2019-11-29T11:40:01.081+0900 I ASIO     [NetworkInterfaceASIO-ShardRegistry-0] Connecting to 172.18.102.13:27019
2019-11-29T11:40:01.084+0900 I ASIO     [NetworkInterfaceASIO-ShardRegistry-0] Successfully connected to 172.18.102.12:27019, took 3ms (1 connections now open to 172.18.102.12:27019)
2019-11-29T11:40:01.084+0900 I ASIO     [NetworkInterfaceASIO-ShardRegistry-0] Successfully connected to 172.18.102.13:27019, took 3ms (2 connections now open to 172.18.102.13:27019)
2019-11-29T11:40:01.084+0900 I ASIO     [NetworkInterfaceASIO-ShardRegistry-0] Successfully connected to 172.18.102.13:27019, took 4ms (2 connections now open to 172.18.102.13:27019)
2019-11-29T11:40:01.087+0900 I NETWORK  [shard registry reload] Starting new replica set monitor for sh00/172.18.102.22:27018,172.18.102.23:27018
2019-11-29T11:40:01.087+0900 I NETWORK  [shard registry reload] Starting new replica set monitor for sh01/172.18.102.27:27018,172.18.102.28:27018
2019-11-29T11:40:01.089+0900 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to 172.18.102.22:27018 (1 connections now open to 172.18.102.22:27018 with a 5 second timeout)
2019-11-29T11:40:01.090+0900 W NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 172.18.102.23:27018, in(checking socket for error after poll), reason: Connection refused
2019-11-29T11:40:01.092+0900 W SHARDING [replSetDistLockPinger] pinging failed for distributed lock pinger :: caused by :: LockStateChangeFailed: findAndModify query predicate didn't match any lock document
2019-11-29T11:40:01.107+0900 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to 172.18.102.27:27018 (1 connections now open to 172.18.102.27:27018 with a 5 second timeout)
2019-11-29T11:40:01.110+0900 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to 172.18.102.28:27018 (1 connections now open to 172.18.102.28:27018 with a 5 second timeout)
2019-11-29T11:40:03.094+0900 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/mongo/data/diagnostic.data'
2019-11-29T11:40:03.112+0900 I REPL     [initandlisten] Rollback ID is 1
2019-11-29T11:40:03.115+0900 F REPL     [initandlisten] Caught exception during replication recovery: Location40415: BSON field 'MinValidDocument.h' is an unknown field.
2019-11-29T11:40:03.115+0900 F -        [initandlisten] terminate() called. An exception is active; attempting to gather more information
2019-11-29T11:40:03.152+0900 F -        [initandlisten] DBException::toString(): Location40415: BSON field 'MinValidDocument.h' is an unknown field.
Actual exception type: mongo::error_details::throwExceptionForStatus(mongo::Status const&)::NonspecificAssertionException

 0x7f153d43d411 0x7f153d43cdf5 0x7f153d531a16 0x7f153d531a61 0x7f153bfd045a 0x7f153c2fbb14 0x7f153c2fc25f 0x7f153bafd5b1 0x7f153bbd9eac 0x7f153bb66269 0x7f153990ec9d 0x7f153bbc9801
----- BEGIN BACKTRACE -----
{"backtrace":[{"b":"7F153B1C8000","o":"2275411","s":"_ZN5mongo15printStackTraceERSo"},{"b":"7F153B1C8000","o":"2274DF5"},{"b":"7F153B1C8000","o":"2369A16","s":"_ZN10__cxxabiv111__terminateEPFvvE"},{"b":"7F153B1C8000","o":"2369A61"},{"b":"7F153B1C8000","o":"E0845A","s":"_ZN5mongo4repl23ReplicationRecoveryImpl16recoverFromOplogEPNS_16OperationContextE"},{"b":"7F153B1C8000","o":"1133B14","s":"_ZN5mongo4repl26ReplicationCoordinatorImpl21_startLoadLocalConfigEPNS_16OperationContextE"},{"b":"7F153B1C8000","o":"113425F","s":"_ZN5mongo4repl26ReplicationCoordinatorImpl7startupEPNS_16OperationContextE"},{"b":"7F153B1C8000","o":"9355B1"},{"b":"7F153B1C8000","o":"A11EAC","s":"_ZN5mongo11mongoDbMainEiPPcS1_"},{"b":"7F153B1C8000","o":"99E269","s":"main"},{"b":"7F15398F0000","o":"1EC9D","s":"__libc_start_main"},{"b":"7F153B1C8000","o":"A01801"}],"processInfo":{ "mongodbVersion" : "3.6.12", "gitVersion" : "c2b9acad0248ca06b14ef1640734b5d0595b55f1", "compiledModules" : [], "uname" : { "sysname" : "Linux", "release" : "2.6.32-131.17.1.el6.x86_64", "version" : "#1 SMP Wed Oct 5 17:19:54 CDT 2011", "machine" : "x86_64" }, "somap" : [ { "b" : "7F153B1C8000", "elfType" : 3, "buildId" : "804901AADA9203BD18DAA9E7C1C14945EECCA0AD" }, { "b" : "7FFFA85F3000", "elfType" : 3, "buildId" : "B90AF308ECD887886097A16108D8BD5991232BBD" }, { "b" : "7F153AD8D000", "path" : "/lib64/libresolv.so.2", "elfType" : 3, "buildId" : "AE7B24A5D3CF932BB2B446B4EC8C5F5C2EF2891C" }, { "b" : "7F153A9AD000", "path" : "/usr/lib64/libcrypto.so.10", "elfType" : 3, "buildId" : "D089593E0BE373CB42C59F1F027BBAB8EFE14004" }, { "b" : "7F153A741000", "path" : "/usr/lib64/libssl.so.10", "elfType" : 3, "buildId" : "814FD6A5B80CE3F46892E55D81584BEE5941EFFE" }, { "b" : "7F153A53D000", "path" : "/lib64/libdl.so.2", "elfType" : 3, "buildId" : "371AF73F6FE95874FAE32A6258581E9A454998A0" }, { "b" : "7F153A335000", "path" : "/lib64/librt.so.1", "elfType" : 3, "buildId" : "5EC0E6BEC7C6E975DBD54BD5712E2DA268287636" }, { "b" : "7F153A0B1000", "path" : "/lib64/libm.so.6", "elfType" : 3, "buildId" : "2CBEB4973361F6E16EFC6D0295F2727B6E3160C6" }, { "b" : "7F1539E9B000", "path" : "/lib64/libgcc_s.so.1", "elfType" : 3, "buildId" : "37BBC893A4E5191243B2640325B41565F654F073" }, { "b" : "7F1539C7F000", "path" : "/lib64/libpthread.so.0", "elfType" : 3, "buildId" : "7FC71D0B10EF7B07C7AAF8180D1274242ED35839" }, { "b" : "7F15398F0000", "path" : "/lib64/libc.so.6", "elfType" : 3, "buildId" : "EC9A3233526A5A6D7A5A7DD90501166D6455DC02" }, { "b" : "7F153AFA6000", "path" : "/lib64/ld-linux-x86-64.so.2", "elfType" : 3, "buildId" : "10893613FF0EE24F3EAC3BBD2889F448CC38604E" }, { "b" : "7F15396DB000", "path" : "/lib64/libz.so.1", "elfType" : 3, "buildId" : "9DD8A788CA4187D2E73B61EF5E09B8D938338A1E" }, { "b" : "7F153949A000", "path" : "/lib64/libgssapi_krb5.so.2", "elfType" : 3, "buildId" : "5C536B63A5C114E90795E093A1FE98F47866C1C2" }, { "b" : "7F15391BB000", "path" : "/lib64/libkrb5.so.3", "elfType" : 3, "buildId" : "3D43E672FEB73D8803EDB032F8C5482EBBD17EF7" }, { "b" : "7F1538FB8000", "path" : "/lib64/libcom_err.so.2", "elfType" : 3, "buildId" : "9E257FB24B29A5816FA6809B1760A43DEC10491C" }, { "b" : "7F1538D8C000", "path" : "/lib64/libk5crypto.so.3", "elfType" : 3, "buildId" : "EDBBE94F8DE978A63CFDABED443AA4C85D804201" }, { "b" : "7F1538B82000", "path" : "/lib64/libkrb5support.so.0", "elfType" : 3, "buildId" : "5F7CCE9F99BBE59F0CED78FB142578C2EC2E2AE8" }, { "b" : "7F1538980000", "path" : "/lib64/libkeyutils.so.1", "elfType" : 3, "buildId" : "D5455DA41EE0E12856ADA694D629B5229BEBA33C" }, { "b" : "7F1538761000", "path" : "/lib64/libselinux.so.1", "elfType" : 3, "buildId" : "C578D70D1C344B02F7C1F2EC895AD9E7EB643982" } ] }}
 mongod(_ZN5mongo15printStackTraceERSo+0x41) [0x7f153d43d411]
 mongod(+0x2274DF5) [0x7f153d43cdf5]
 mongod(_ZN10__cxxabiv111__terminateEPFvvE+0x6) [0x7f153d531a16]
 mongod(+0x2369A61) [0x7f153d531a61]
 mongod(_ZN5mongo4repl23ReplicationRecoveryImpl16recoverFromOplogEPNS_16OperationContextE+0xBDA) [0x7f153bfd045a]
 mongod(_ZN5mongo4repl26ReplicationCoordinatorImpl21_startLoadLocalConfigEPNS_16OperationContextE+0x4C4) [0x7f153c2fbb14]
 mongod(_ZN5mongo4repl26ReplicationCoordinatorImpl7startupEPNS_16OperationContextE+0x1DF) [0x7f153c2fc25f]
 mongod(+0x9355B1) [0x7f153bafd5b1]
 mongod(_ZN5mongo11mongoDbMainEiPPcS1_+0x86C) [0x7f153bbd9eac]
 mongod(main+0x9) [0x7f153bb66269]
 libc.so.6(__libc_start_main+0xFD) [0x7f153990ec9d]
 mongod(+0xA01801) [0x7f153bbc9801]
-----  END BACKTRACE  -----

我应该创建一个<html> <head> <meta charset="UTF-8"> <title> Game Library</title> <link href="css/style.css" type="text/css" rel="stylesheet"> </head> <body> <div id="wrapper"> <div id="search"> <img id="del" src="img/delete.jpg" alt="Error"> <a class="A" href="index.php"><img class="AR" src="img/src.jpg" title="Search library"></a> <a class="A" href="insert.php"><img class="AR" src="img/add.png" title="Add game"></a> <div id="results"> <?php require("inc/connection.php"); $query = "SELECT * FROM Library"; $result = mysqli_query($conn,$query); if(mysqli_num_rows($result)>0){ while($row = mysqli_fetch_assoc($result)){ ?><div id="results"> <form action="inc/delete.php" method="GET"> <input type="checkbox" name="checkbox[]" value="<?php echo $row['ID'] ?>"> <p id="p1">Name: <?php echo $row['Name']?>;</p> <p>Genre: <?php echo $row['Genre']?></p> <p>Release date: <?php echo $row['Release_date']?></p> <p>Publisher: <?php echo $row['Publisher']?>:</p> <p>Platforms: <?php echo $row['Platforms']?></p> </div> <?php }?> <input type="submit" name = "submit" value = "Submit"></form> <?php }else{ echo "No results!"; } </div> </div> </div> </body> </html> 脚本,该脚本允许我使用复选框和提交按钮删除多行。有人可以帮我这个忙吗?老实说,我不知道如何完成此操作……。

4 个答案:

答案 0 :(得分:1)

需要首先将表单方法设置为“ POST”

因此,修改

<form action="inc/delete.php" method="GET">

收件人:

<form action="inc/delete.php" method="post">

inc/delete.php中,

if (isset($_POST['submit'])){ // Check if form is submitted.
 if (! empty($_POST['checkbox'])){ // Check if Checkbox is checked.
  // Loop over the checkbox and get selected ids.
  foreach($_POST['checkbox'] as $checkbox_id){
    echo $checkbox_id."<br/>";
    // Add your delete query here.
  }
 }
}

答案 1 :(得分:1)

因此,解决方案是您获得delete脚本array的ID。您可以解析该数组并为每个id执行DELETE查询:

if(isset($_POST['checkbox']))
{
    foreach($_POST['checkbox'] as $val)
    {
        $stmt = $conn->prepare("DELETE FROM Library WHERE id = ?");
        $stmt->bind_param('i', $val);
        $stmt->execute();
    }
}

答案 2 :(得分:0)

inc / delete.php

<?php
if(isset($_POST['submit'])){//to run PHP script on submit
 if(!empty($_POST['checkbox'])){
  // Loop to store and display values of individual checked checkbox.
  foreach($_POST['checkbox'] as $row_id){
    echo $row_id."</br>";
    // DELETE QUERY HERE
  }
 }
}
?>

答案 3 :(得分:0)

<?php 
    if(isset($_POST['submit']))
    {
        if(!empty($_POST['checkbox']))
        {
            foreach ($_POST['checkbox'] as $key => $check)
            {
                // delete query
            }
        }
    }
?>

注意:您无法在第n行关闭PHP。 40.请确保您的PHP标记已关闭。