rdkurth Posted July 13, 2014 Share Posted July 13, 2014 I am having a problem making this work. It adds and deletes but it does it by passing the date directly to the PHP files and refreshing the screen. I want it to do it through the jquery Ajax script. This should work according to what I have read but no mater what I try the jquery script does not work. <html><head><script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script></head><body><script type="text/javascript">$(document).ready(function(){$('MySignform').submit(function(e) {e.preventDefault();$.ajax({type: 'POST',url: $('MySignform').prop('action'),data: $('MySignform').serialize(),success: function() {alert("It worked!");}});});});</script><script type="text/javascript">$(document).ready(function(){$('DelForm').submit(function(e) {e.preventDefault();$.ajax({type: 'POST',url: $('DelForm').prop('action'),data: $('DelForm').serialize(),success: function() {alert("It worked!");}});});});</script><br /><br /><br /><center><form name="MySignform" action="addsigningfee.php" method="post"><label>Signing fee</label><input name="signingfee" type="text" id="signingfee"/><input name="pid" type="hidden" value="7"/><p></p><button id="form-submit" type="submit">Save</button></form><br /><div id="result"></div><br /><form name="DelForm" action="delsigningfee.php" method="post"><select name="signingfee"><?phprequire_once("connect.php");foreach ($db->query("SELECT signingfee,id FROM options WHERE signingfee <> '' AND pid = '7'") as $row){echo "<option value=" . $row['id'] . ">" . $row['signingfee'] . "</option>";}?></select><p></p><button type="submit" >Delete</button></form></center></body></html> Adding and Deleteing mysql date using jquery AjaxI am having a problem making this work. It adds and deletes but it does it by passing the date directly to the PHP files and refreshing the screen. I want it to do it through the jquery Ajax script. This should work according to what I have read but no mater what I try the jquery script does not work. Some help getting me In the right direction would be great. Code:<html><head><script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script></head><body><script type="text/javascript">$(document).ready(function(){$('MySignform').submit(function(e) {e.preventDefault();$.ajax({type: 'POST',url: $('MySignform').prop('action'),data: $('MySignform').serialize(),success: function() {alert("It worked!");}});});});</script><script type="text/javascript">$(document).ready(function(){$('DelForm').submit(function(e) {e.preventDefault();$.ajax({type: 'POST',url: $('DelForm').prop('action'),data: $('DelForm').serialize(),success: function() {alert("It worked!");}});});});</script><br /><br /><br /><center><form name="MySignform" action="addsigningfee.php" method="post"><label>Signing fee</label><input name="signingfee" type="text" id="signingfee"/><input name="pid" type="hidden" value="7"/><p></p><button id="form-submit" type="submit">Save</button></form><br /><div id="result"></div><br /><form name="DelForm" action="delsigningfee.php" method="post"><select name="signingfee"><?phprequire_once("connect.php");foreach ($db->query("SELECT signingfee,id FROM options WHERE signingfee <> '' AND pid = '7'") as $row){echo "<option value=" . $row['id'] . ">" . $row['signingfee'] . "</option>";}?></select><p></p><button type="submit" >Delete</button></form></center></body></html> addsigningfee.php <?php require_once("connect.php"); //print_r($_POST); //exit; $stmt = $db->prepare("INSERT INTO options(signingfee,pid)values(?,?)"); $stmt->bindParam(1, $_POST['signingfee'], PDO::PARAM_STR, 250); $stmt->bindParam(2, $_POST['pid'], PDO::PARAM_INT, 11); $stmt->execute(); ?> delsigningfee.php <?php require_once("connect.php"); $id = $_POST['signingfee']; $db->exec("DELETE FROM options WHERE id = '$id'"); ?> Link to comment https://forums.phpfreaks.com/topic/289803-adding-and-deleteing-mysql-date-using-jquery-ajax/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.