I'm trying to update a database by using jQuery. The function works just fine, but only once. I have to refresh the page and clear the cache if I want to update the database again. I'm using MODX Revolution, I'm not sure if that has anything to do with this problem. Here is the code:
<html>
<head>
<script language="javascript" type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$('#paina').submit( function updateTitle() {
var mail = $("#output").val();
$.ajax({
type: "POST",
url: "gettable.php",
data: "mail="+ mail,
cache: false,
success: function(data){
alert(mail);
}
});
return false;
});
});
</script>
<form id="paina" name="test" action="javascript:updateTitle()" method="post">
<input type="text" id="output">
<input type="Submit" value="Update">
</form>
</body>
</html>
PHP:
<?php
$mail=$_POST["mail"];
$mysqli = mysqli_connect("url", "user", "password", "database_name");
mysqli_query($mysqli, "UPDATE modx_site_content SET pagetitle='$mail' WHERE longtitle='jee'");
echo "Updated!";
$mysqli->close();