1

I wanna run following query on function DeleteCus by clicking on a button.I tried following code for that.bt it is not working.

getting http://localhost/AdminLTE-2.1.1/CusRegReport.php?id=134 url after running notification.php getting error 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); 
}

?>
4
  • onclick ="window.location.href ='PHP/notification.php?hello=true'" > Commented Nov 18, 2015 at 10:21
  • 1
    You have an extra "= href" in your code. Remove that. Commented Nov 18, 2015 at 10:21
  • 1
    where do you print $a variable? Commented Nov 18, 2015 at 10:25
  • I corrected that one.but um getting error Undefined index: id in lin 67 (line 67 is in the function DleteCus $id=$_GET['id'];) how can i directly call the php function without changing the URL.I think the error occurs because of the URL changing to "localhost/AdminLTE-2.1.1/PHP/notification.php?hello=true" when running the code Commented Nov 18, 2015 at 11:01

5 Answers 5

2

Please replace the button code with the following code :

<button type="button"  id = "button" class="btn btn-danger" data-dismiss="modal" onclick ="window.location.href='PHP/notification.php?hello=true'" />
Sign up to request clarification or add additional context in comments.

1 Comment

actually I tried this.but um getting error Undefined index: id in lin 67 (line 67 is in the function DleteCus $id=$_GET['id'];
1

TRY this code for button

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

Comments

1

remove extra href from button onclick event window.location.href ='PHP/notification.php?hello=true

try this:-

Comments

1

try

<button type="button"  id = "button" class="btn btn-danger" data-dismiss="modal" 
onclick="javascript:window.location.href='www.exampe.com/PHP/notification.php?hello=true&id=<?php echo $_GET['id'];?>'; return false;" >

also in your function

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

when you are calling your function change it

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


}

4 Comments

-I tried this one also.but um getting error Undefined index: id in lin 67 (line 67 is in the function DleteCus $id=$_GET['id'];) how can i directly call the php function without changing the URL.I think the error occurs because of the URL changing to "localhost/AdminLTE-2.1.1/PHP/notification.php?hello=true"; when running the code – IsharaRA
Thanks,its working,But error occured. $r = mysqli_query($dbc,$sql); // line 68 } it'saying Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\AdminLTE-2.1.1\PHP\notification.php on line 68
please comment result of echo $sql = "DELETE FROM customer WHERE customer.customer_id = '$id'";
tried & no errors occur.bt nothing happens in my database.since the query is perfectly running on phpmyadmin it has no error.is there any problem with my code?
1

You have $id = $_GET['id']; in method DeleteCus, but you didn't pass that parameter in your link in the button PHP/notification.php?hello=true. So, it should be <button type="button" id = "button" class="btn btn-danger" data-dismiss="modal" onclick ="window.location.href ='PHP/notification.php?hello=true&id=XXX'">. That's why it returns undefined index id in calling PHP method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.