(只使用php或javascript)所以我有一个待办事项列表,从数据库中加载用户的任务并将它们显示为列表项,每个显示的任务旁边都有一个删除按钮,我想从数据库中删除该任务当我单击旁边的删除按钮时,我在数据库用户(id,uid,email,pwd)和任务(id,content,useruid)下面是代码:`
<div class="tasks">
<ul id="myUl">';
require 'includes/dbh.inc.php';
$sql = "SELECT * FROM tasks WHERE useruid=?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt,$sql) ) {
header("location: ../main.php?errosqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt,"s", $_SESSION['useruid'] );
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if( mysqli_num_rows ( $result ) > 0 ){
while ( $row = mysqli_fetch_array($result)){
echo '<li name="'.$row["id"].'"><button type="button" name="checked" title="Mark as completed" class="'.$row["id"].' checked"><i class="fa fa-check"></i></button>'.$row["content"].'<button id="'.$row["id"].'" onclick="deleteTask(this.id)" name="close" title="Delete" class="close '.$row["id"].'"><i class="fa fa-times"></i></button></li>';
}
}
}
echo '
</ul>
<br>
</div>
<div class="completed">
<ul id="myUl1">
</ul>
</div>
</form> `
1条答案
按热度按时间p1iqtdky1#
使用ajax`
服务器端使用post方法获取id,然后使用sqldelete查询