I'm searching for a way to update my Database without having to post the whole page.
I'm trying to keep this as simple as possible.
I'm building a table with with some information in the database in question. When I click on a TD, I switch the content in the TD into a textbox, and on the onblur event of that textbox I want to update that specific field in the DB.
I need to request a POST on another URL (or on the same as long as it doesn't refresh the whole page) to make the query to update the field.
What I have so far that doesn't work... (assume that the function's parameters are okay)
file.js:
function update_configs(c_value, c_id, c_field) {
$.ajax({
url: "/config_update.php",
type: "post",
data: { value: c_value, id: c_id, field: c_field }
});
}
config_update.php:
$conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->query("UPDATE table SET " . $_POST['field'] . " = " . $_POST['value'] . " WHERE id = " . $_POST['id']);