javascript - 在按钮 OnClick 中运行 php 函数(不提交)

标签 javascript php jquery mysql

我想通过单击一个按钮来运行对函数 DeleteCus 的查询。我为此尝试了以下代码。但它不起作用。

获取 http://localhost/AdminLTE-2.1.1/CusRegReport.php?id=134运行 notification.php 后的 url 出现错误 Undefined index: id in lin 67

<button type="button"  id = "button" class="btn btn-danger" data-dismiss="modal" onclick ="window.location.href = href='PHP/notification.php?hello=true'">

<?php


 if (isset($_GET['hello'])) {
DeleteCus();


}

session_start();
$dbc = mysqli_connect('localhost','root','','dashboard') or die(mysqli_connect_error(''));

function notification(){
    global $dbc;
    $query = "SELECT `customer_id`, `customer_name` FROM `customer` WHERE `confirmation`IS NULL LIMIT 0, 30 ";
    $result = mysqli_query($dbc,$query);        
    while($row=mysqli_fetch_array($result))
    {
        echo "<a href='CusRegReport.php?id=" . $row['customer_id'] . "'><i class='fa fa-users text-red'>&nbsp;&nbsp;" . $row['customer_name'] . "&nbsp;&nbsp; needs to register</i></a>";        
     $_SESSION["count"] =mysqli_num_rows($result);  

    }

}

function RegReport(){
    global $dbc; 



    $id = $_GET['id'];  

   // $id = $mysqli->real_escape_string ($id);   

    $sql = "SELECT * FROM `customer` WHERE `customer_id` = '$id'";
    $r = mysqli_query($dbc,$sql);
    while($line=mysqli_fetch_array($r))
    {
        $a= "<br/>" . $line['customer_name'] . "<br/>" . $line['ad_line_one'] .$line['ad_line_two'] .$line['ad_line_three'] .$line['web'] .$line['pub_pvt'] .$line['reg_no'] .$line['tax_no'] .$line['description'] .$line['attachments'] .$line['contact_name'] .$line['contact_salutation'] .$line['contact_designation'] .$line['contact_email'] .$line['contact_tp1'] .$line['contact_tp2'] .$line['md_fname'] .$line['md_lname'] .$line['md_email'] .$line['date']. "</a>";  

    }
}
function DeleteCus(){
global $dbc;   
$id =  $_GET['id'];
$sql = "DELETE FROM `customer` WHERE `customer`.`customer_id` = '$id'";
  $r = mysqli_query($dbc,$sql); 
}

?>

最佳答案

请将按钮代码替换为以下代码:

<button type="button"  id = "button" class="btn btn-danger" data-dismiss="modal" onclick ="window.location.href='PHP/notification.php?hello=true'" />

关于javascript - 在按钮 OnClick 中运行 php 函数(不提交),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33777382/

相关文章:

javascript - 如何在 jQuery 中对特定事件顺序应用函数?

javascript - 我可以将 ReactJS Native 的值分配给 Swift 全局变量吗?如果是这样,如何?

javascript - 如何更新 React-Native ListView ?

php - SimpleXMLElement : Retrieving Namespace Attribute

PHP + SQL 脚本 - 防止 SQL 注入(inject)

php - 在 nginx 中为 symfony2 创建一个 block

javascript - 如何在 Angular JS 中以编程方式美化 JSON?

javascript - jQuery:确定[服务器的]文档根目录

javascript - 检查值 select2 是否为空

javascript - 使用象形图示例