Reputation: 13206
I have the following AJAX script which doesn't seem to be firing. Can anybody please tell me what's wrong with it?
form.php
<script type = "text/javascript"> $(document).ready(function () {
$('#updatebtn1').click(function () {
$('#result1').show('slow').delay(4000).hide('slow')
$.post('process.php', $('#updateform1').serialize())
});
});
</script>
<form id="updateform1">
<div class="tbl_header">Timetable Support Website</div>Due Date:
<script>
$(function() {
$("#datepicker1").datepicker({
minDate: -0,
dateFormat: 'dd/mm/yy',
maxDate: new Date(2013, 1, 22)
})
});
</script>
<input type="text" id="datepicker1" style="width: 100px;
height: 10px;" value="18/02/2013" name="duedate" /> Status:
<select style="width: 125px;" name="status">
<option>Pending</option>
<option>----</option>
<option>Pending</option>
<option>In Progress</option>
<option>Complete</option>
</select>
<input type="hidden" name="id" value="1">
<input type="button" id="updatebtn1" value="Update" style="width: 100px;"
class="pmbtn" />
</form>
<div id="result1" style="display: none; color: red">Update successful!</div>
process.php
<?php
$duedate = $_POST["duedate"];
$status = $_POST["status"];
$id = $_POST["id"];
$sql = "UPDATE pm_schedule SET duedate=?, status=?, id=? WHERE id=?";
$q = $pdo->prepare($sql);
$q->execute(array($duedate,$status,$id));
?>
Upvotes: 0
Views: 116
Reputation: 24383
I'm not overly familiar with positional place holders (I always used named place holders), but I'm assuming you need to do
$q->execute(array($duedate,$status,$id,$id));
since $id
is used twice. MySQL doesn't know what you want for the final place holder. It's likely throwing some sort of error that the place holder count doesn't match.
Try adding this to your database handle:
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
and then echoing the output of process.php
back to the main page.
Upvotes: 1