Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<?php

    $query = "SELECT * FROM darb ORDER BY darb_id DESC ";
    $select_darb = mysqli_query($connection, $query);

    while ($row = mysqli_fetch_assoc($select_darb)) {
        $darb_id            = $row['darb_id'];
        $darb_user          = $row['darb_user'];
        $darb_title         = $row['darb_title'];
        $darb_status        = $row['darb_status'];
        $darb_date          = $row['darb_date'];
        $darb_work          = $row['darb_work'];
        $darb_finish        = $row['darb_finish'];
        $darb_result        = $row['darb_result'];
        $darb_fileUpload    = $row['darb_fileUpload'];
        $darb_payment       = $row['darb_payment'];

        echo "<tr>"; ?>


What I have tried:

I have tried a lot of advice online but couldn't resolve this problem.
Posted
Updated 14-Jun-20 15:14pm
v6
Comments
F-ES Sitecore 1-Jun-20 6:18am    
Does your click event get called?
Matas - developer 1-Jun-20 6:34am    
I think so, Popup modal opens, but then I press delete button with delete url it’s just refresh page.
F-ES Sitecore 1-Jun-20 7:08am    
According to your code it changes the delete link to go to darb.php with a "delete" param of the id. If your site redirects to that url when you click the delete link then it is doing what it is coded to do.
Andre Oosthuizen 9-Jun-20 8:00am    
Show us your code in darb.php as well, you are calling the page but it seems that nothing happens (no deletion) in your php page, code seems to be wrong tehre as this is where the deletion will occur.
Matas - developer 9-Jun-20 20:06pm    
I add darb.php code

1 solution

Quote:
it's just refreshing but not deleting
That is a basic problem with jQuery and other JavaScript event handlers on the page. When you press a button, a JavaScript event is triggered that you attach to it, but that does not prevent the browser to perform the default action associated with the element.

For a button or input[type='submit'], the browser will post the content to the server and reload the page. In normal cases, a page is refreshed unless there is an action attribute applied to the form (if the element is within a form).

An easy way to handle this is to add a event.preventDefault() to the handler, which prevents the browser from "refreshing" the page. So your JavaScript code should be like:

JavaScript
$(document).ready(function(){
  $(".delete_link").on('click', function(){
      event.preventDefault(); // <-- this here

      var id = $(this).attr("rel");
      var delete_url = "darb.php?delete="+ id;
      $(".modal_delete_link").attr("href", delete_url);
      $("#myModal").modal('show');
  });
});
Now your code would run and show the modal—your modal will take it from here as the browser will not reload the page.

Read more about event.preventDefault here[^].
 
Share this answer
 
v2
Comments
Matas - developer 9-Jun-20 20:40pm    
Thank you so much for help, but it's still the same, not deleting, maybe something I messed up, and still not found a problem...
Afzaal Ahmad Zeeshan 9-Jun-20 22:43pm    
If the page is not loading, then you can do two things:

1. Check if the request is being sent to the page you have added (check under the Network tab in your browser developer tools).
2. If the request is being made, then debug the code and see where (and why) it fails.

More likely, it would help you decrease the area of the error. If you see a 500 in the Network tab, then it is a problem with the PHP code execution—otherwise a problem with the SQL logic. These are just a few starters. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900