I am using the X-Editable plugin in my php application to update the fields of my table and use the POST file to update the database.
Here is the form code:
<table id="restaurant" class="table table-bordered table-striped">
<tbody>
<?php
echo '
<tr>
<td style="width:15%">Restaurant name</td>
<td style="width:50%"><a href="#" id="name" data-type="text" data-pk="'. escape($arrValues[$i]->r_id) .'" data-name="name" data-placeholder="Required" data-original-title="Enter Restaurant Name" class="editable editable-click" style="display: inline;">'. escape($arrValues[$i]->name) .'</a></td>
<td style="width:35%"><span class="text-muted">Enter restaurant name.</span></td>
</tr>';
?>
</tbody>
</table>
Here is the X-editable JS that I use at the bottom of the page:
<script>
jQuery(document).ready(function() {
FormEditable.init();
$(function(){
$('#name').editable({
url: 'post.php'
});
});
});
</script>
Here is the contents of my Post.php file:
<?php
require 'core/init.php';
$pk = $_POST['pk'];
$name = $_POST['name'];
$value = $_POST['value'];
if (!empty($value)){
$result = mysql_query('update Restaurants set '.mysql_escape_string($name).'="'.mysql_escape_string($value).'" where r_id = "'.mysql_escape_string($pk).'"');
print_r($_POST);
} else {
header('HTTP 400 Bad Request', true, 400);
echo "This field is required!";
}
?>
When I update the field in the application, the value changes in the DOM, but the value is not updated in the database. This is my first time using the X-Editable plugin, and I'm not very good at JS AJAX calls. Can someone please let me know how I can debug this and find out why my value is not popped into the database.
Any help would be greatly appreciated.
Anton