php 删除选项不起作用

标签 php jquery mysql ajax

嗨,我正在尝试在我的网站中使用 php 创建删除确认框,但我遇到了一些问题。如果我单击“取消”按钮,它也会删除数据库中的行。索引页面是用jquery设计的

这是我用于删除选项的 php 代码?

<?php

    echo "<script language='javascript' type='text/javascript'>var x=confirm('Successfully Deleted!')</script>";

    if(x==true)
    {
    echo"deleted";
    include ("dbconnection.php");
$pid=$_GET['pid'];
$sql="DELETE FROM voters where id=$pid";
$res = mysql_query($sql) or die(mysql_error()); 
echo "<script language='javascript'  type='text/javascript'>window.open('index.php','_self')</script>";
}
else
{
echo"cancelled";
}
   ?>

这是我的 jquery 代码...

$str.="<thead><tr><th>ID</th><th>Card No</th><th>Name</th><th>Mob_num</th><th>Email</th><th>Action</th></tr></thead><tbody>";
                    while($row = mysql_fetch_array($res)){
                        $str.="<tr><td><center>".$row['id']."</center></td>";
                        $str.="<td>".$row['vcardno']."</td>";
                        $str.="<td>".$row['vname']."</td>";
                        $str.="<td>".$row['mob_num']."</td>";
                        $str.="<td>".$row['email']."</td>";
                        $str.="<td><center><a class='fancybox fancybox.ajax' href='viewstudent.php?ppid=".$row['id']."' onclick='return update()'><img src = 'images/view.png' height='30' width='30' alt = 'view' title = 'view'/></a><a class='fancybox fancybox.ajax' href='updatestudent.php?ppid=".$row['id']."' onclick='return update()'><img src = 'images/edit-icon.png' height='30' width='30' alt = 'edit' title = 'edit'/></a><a href='delete1.php?pid=".$row['id']."' onclick='return deleteItem()' ><img src = 'images/edit_delete.png' height='30' width='30' alt = 'delete' title = 'delete'/></a></center></td></tr>";
                    }

谢谢..

最佳答案

x是jquery的变量。您无法在 php 代码中访问它。您需要通过 ajax 调用来访问它(这是一种方法)。

关于php 删除选项不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21798277/

相关文章:

php - 'root' @ 'localhost' 拒绝访问数据库 'mysql' 即使我已经使用 root 用户名和密码登录 phpmyadmin

php - API 平台 : Filtering Custom Data Provider

php - 使用 php 清除表中的所有条目

php - 使用 where 条件连接查询 codeigniter 返回所有行

php - 隐藏除索引之外的每个页面上的 div

php - PHP 是否有超出我设置的固有内存限制?

c# - 将 Json 数据打印为 Html 表

javascript - VS 2010 Javascript 智能感知不工作

javascript - 如何检查 jQuery 表单循环中的单选按钮和复选框是否被选中?

mysql - MySql查询格式化数据的方法