首页 > 解决方案 > 使用带有 javascript 和 php 的确认框

问题描述

在删除发生之前,我需要包含一个确认框。我在这里和谷歌研究了这一切,找不到可行的选择,所以我希望有人能教我正确的方法来解决这个问题。

在引导程序中的表中显示删除按钮的函数...


  function operateFormatter(value, row, index) {
    return [

      '<a class="remove" onclick="" href="deleteVendor.php?vendor_id=' + row.id + '" title="Remove">',
      '<i class="fa fa-trash"></i>',
      '</a>',

      '<a class="view" href="viewVendor.php?vendor_id=' + row.id + '" title="View">',
      '<i class="fa fa-eye"></i>',
      '</a>'
    ].join('')
  }

删除供应商.php

<?php
session_start();
/* Include the database connection file (remember to change the connection parameters) */
require './db_inc.php';

/* Include the Account class file */
require './account_class.php';
/* Create a new Account object */
$account = new Account();
$user = $_SESSION['username'];
$login = FALSE;
$id = $account->getIdFromName($user);
$vendor_id = $_GET['vendor_id'];
try
{
    $login = $account->sessionLogin();



}
catch (Exception $e)
{
    echo $e->getMessage();
    die();
}

if ($login)
{
}
else
{
    header('Location: ./index.php');
} 


        $query = "DELETE FROM vendors.vendor_data WHERE id=$vendor_id";

        /* Execute the query */
        try
        {
            $res = $pdo->prepare($query);
            $res->execute();


        }
        catch (PDOException $e)
        {
           /* If there is a PDO exception, throw a standard exception */
           throw new Exception($e);
        }


?>

标签: javascriptphp

解决方案


您可以为此使用确认功能。

<a href="delete.php" onclick="return confirm('Are you sure?')">Click To Delete</a>


推荐阅读