I want my database to be updated when a button on my webpage is pressed without the page being refreshed. I used an AJAX function to do so, but I noticed that it also executes whenever I reload the page.
What I've done so far: I created an ajax function inside script code to execute whenever the button is clicked and it works just fine. But when I reload the page same thing happens as if I pressed the button.
Here's the script:
$(document).ready(function() {
$('#delAddress').click(function() {
<?php
$sql = "UPDATE billinginfo SET
fullname = '',
address1 = '',
address2 = '',
zip = '',
city = '',
country = ''
WHERE username = '$usernameProfile';";
$result = mysqli_query($dbProfile, $sql);
?>
return false;
});
});
I want it to execute just as it does right now but without it executing when I reload the page.