1

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.

4
  • 2
    You're basically doing "here, fly to China, ask the person if they want to do something, and while you're flying over there, I'll just keep on trucking with the rest of the code". What you want is not possible without fundamentally restructuring your code. Commented Oct 21, 2014 at 15:43
  • I wonder, how it is working in windows. Commented Oct 21, 2014 at 16:09
  • You should rather use ajax. Commented Oct 21, 2014 at 16:26
  • I just want to confirm from the user on what fields he is updating, I achieved this by calling a javascript function onclick(while submitting) and getting the confirmation from the user and only submitting the form on "OK" and exiting on "Cancel". Thanks anyways.. Commented Oct 24, 2014 at 6:32

1 Answer 1

2

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.

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

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.