Jump to content

Adding and Deleteing mysql date using jquery Ajax


rdkurth

Recommended Posts

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">

<?php
require_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 Ajax

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. 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">

<?php
require_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_STR250);
        
$stmt->bindParam(2$_POST['pid'], PDO::PARAM_INT11);
        
$stmt->execute();

?>
 
delsigningfee.php
<?php
require_once("connect.php");


        
$id $_POST['signingfee'];
        
$db->exec("DELETE FROM options WHERE id = '$id'");
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.