1

In table (that contains records, customers credentials, from my db) I have a delete button for each row.
I want that if I click on the delete button, this will delete the row, passing the ID of the record to the deletecustomer.php
When I click on the delete button, I have a ajax modal that ask if you want to confirm the action or not.
The problem is that if I click on CONFIRM (in the modal), my modal will go in delete-utente.php (where I have the query for the delete of the row) but the ID isn't passed.
In delete-utente.php I have a message if the query it's ok (delete complete), and another message if the delete can't be done.
After I click confirm I always have the OK message, but the customer has not been deleted.
I guess that the problem is not the deletecustomer.php because if I use a simple javascript alert, the query it's ok and I pass the identifier successful, but with the ajax modal, the identifier is not passed.

It's the first time that I use ajax, so I think that the problem it's ajax code.

code of the table in my main page (newcustomer.php)

<table class="simple-table responsive-table" method="POST" id="customer-list">
//code thead
//rows rows..
<?php echo '<button type="input" class="button icon-trash with-tooltip confirm" onclick="openConfirm()" href="deletecustomer.php?customerid='.$idcustomer.'" title="Delete"></button>'; ?>
//....
</table>

ajax modal

function openConfirm()
        {
            $.modal.confirm('Sicuri di voler cancellare il cliente?', function()
            {
                window.location.href = "deletecustomer.php"; //the php file where I have the delete query


            }, function()
            {
                window.location.href = "newcustomer.php";

            });
        };

and I take the values in my deletecustomer.php like this

$customeridd=(int) $_GET['customerid']; 

Sorry if is a stupid mistake or a stupid question ^^" And thank in advice

2 Answers 2

1

You can use like this :

<?php 
  echo '<button type="input" class="button icon-trash with-tooltip confirm" onclick="openConfirm('.$idcustomer.')" href="deletecustomer.php?customerid='.$idcustomer.'" title="Delete">button</button>'; 
?>

And

function openConfirm(id)
    {
        alert(id);
        $.modal.confirm('Sicuri di voler cancellare il cliente?', function()
        {
            window.location.href = "deletecustomer.php?customerid="+id; //the php file where I have the delete query


        }, function()
        {
            window.location.href = "newcustomer.php";

        });
    };
Sign up to request clarification or add additional context in comments.

Comments

0

Try the following code:

<?php echo '<a class="button icon-trash with-tooltip confirm" onclick="return confirm(\'Are you sure?\');" href="deletecustomer.php?customerid='.$idcustomer.'">Delete</a>'; ?>

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.