mysqli中的回声脚本警报

时间:2013-12-02 10:51:39

标签: php mysql mysqli

您好我正在尝试制作一个删除脚本,当用户点击删除它时工作正常删除该帖子并弹出更改该帖子已被删除然后重定向到他们的主页但是在将此脚本转换为mysqli后它正在工作很好,但它没有显示弹出窗口改变,也没有重定向。

这是我的delete.php脚本

<?php 

$con=mysqli_connect("localhost","root","123","user");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
if(isset($_GET['del'])){

    $delete_id = $_GET['del'];

$delete_query = mysqli_query($con,"delete from save_data where ID='$delete_id'")
    or die(mysql_error()); 

if (mysqli_query($con, $delete_query)) {

echo "<script>alert('Image Has been Deleted')</script>";
    echo "<script>window.open('pimage.php','_self')</script>";

    }

}

?>

3 个答案:

答案 0 :(得分:3)

为什么要执行两次查询?你忘记了脚本标签中的分号

尝试这样做..

      $delete_query = mysqli_query($con,"delete from save_data where ID='$delete_id'")
or die(mysql_error()); 

  if ($delete_query) {

     echo "<script>alert('Image Has been Deleted');</script>";
     echo "<script>window.open('pimage.php','_self');</script>";
}

希望它可以解决您的问题

答案 1 :(得分:0)

你能试试吗,你错过了脚本中的;屁股。您也已多次执行mysqli_query,而是使用一次。

    if ($delete_query) {            
           echo "<script>alert('Image Has been Deleted'); window.open('pimage.php','_self');</script>"; 
    }

答案 2 :(得分:0)

变化:

echo "<script>alert('Image Has been Deleted')</script>";
echo "<script>window.open('pimage.php','_self')</script>";

要:

echo "<script>alert('Image Has been Deleted');</script>";
echo "<script>window.open('pimage.php','_self');</script>";

此外,您正在运行两次SQL语句,因此它将始终为false,因为它已被删除。因此,请将$delete_query更改为:

$delete_query = "delete from save_data where ID='$delete_id'");