Headrun
Headrun

Reputation: 129

Exit php script based on the response from javascript confirm

I am taking the values from html form and doing some manipulations in php and updating the record of a mysql table. Before updating, i am asking the user to "confirm" using javascript. If the user press "Cancel" i don't want the record to be updated.

I have tried the following,

... some php code here
<script type=text/javascript>
    var to_disp = <?php echo json_encode($u_fields);?>;
    var r = confirm("Updating the fields >> " + to_disp.join());
    if (r != true){
        window.location.href = some-url;
    }
</script>

...updating the record here

Note: This works fine in windows. But, when moved to linux, this isn't working the page is re-directed to the mentioned url but the record is also getting updated.

Upvotes: 1

Views: 238

Answers (1)

Tom
Tom

Reputation: 21

PHP code is run server-side, Javascript client side.

For example: Create a client side form with a submit button "Confirm". Send this to the client first, then for the action of this form create a php code file which will then update/not update the record.

Upvotes: 2

Related Questions