我是JavaScript新手,我有一个问题。我想通过检查从数据库中删除数据。通过我的代码,我设法擦除了我的数据,但是检查不起作用。
我第一次在函数msg()中返回的值为true,但似乎不起作用,所以我添加了
window.location = "delete.php?"
但这不能解决我的问题。谁能展示如何解决这个问题?
我的php代码(delete.php)在这里:
<?php
$con = mysqli_connect("localhost", "root", "", "mybase");
if(isset($_GET["btn"])){
$sql = 'DELETE FROM user;';
if(mysqli_query($con, $sql)==1){
//echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
}
?>
我的html代码在这里:
<form action="delete.php" method="get">
<input type="submit" value="Delete your base" onclick="msg()" name="btn">
</form>
</div>
</body>
</html>
<script>
function msg(){
var my = confirm("Are you sure you want to delete?");
if (my) {
//return true;
window.location = "delete.php?"
}
}
</script>
答案 0 :(得分:0)
在msg()中设置要删除的ID。
type Node<T> = {
type: 'node',
node: Array<Filter<T>>;
}
type Method<T> = {
type: 'method',
method: Condition<T>;
}
type NodeOrMethod<T> = Node<T> | Method<T>;
cost a: NodeOrMethod<T> = { // valid
type: 'node',
node: [...]
}
cost b: NodeOrMethod<T> = { // valid
type: 'method',
method: ...
}
cost c: NodeOrMethod<T> = { // type error
type: 'method',
node: [...],
method: ...
}
Delete.php
<form action="delete.php" method="get">
<input type="submit" value="Delete your base" onclick="msg(<?php echo $id; ?>)" name="btn">
</form>
</div>
</body>
</html>
<script>
function msg(id){
var my = confirm("Are you sure you want to delete?");
if (my) {
//return true;
window.location = "delete.php?deleteid="+id;
}
}
</script>