For my final project, i'm trying to make my html tables editable by users, with updating data in MySQL. I've found in web a few js scripts for such case but no one works as needed. My result - editable table with correct data, but new entered data are not saved in the sql table. What I'm missing?

Data for table:


    $doctors = CS50::query("SELECT id, name, mob, hours FROM doctors");

    render("doctors_form.php", ["title" => "Doctors", "doctors" => $doctors]);

This is "saveInlineEdit" script I've used

    function saveInlineEdit(editableObj,column,id) {
    // no change change made then return false
    if($(editableObj).attr('data-old_value') === editableObj.innerHTML)
    return false;
    // send ajax to update value
    $(editableObj).css("background","#FFF url(loader.gif) no-repeat right");
        url: "saveInlineEdit.php",
        cache: false,
        success: function(response)  {
            // set updated value as old value

This is html table (js script is in this file on the top):


<?php foreach ($doctors as $doctors): ?>

        <td contenteditable="true" data-old_value="<?= $doctors["name"]?>"
        <td contenteditable="true" data-old_value="<?= $doctors["mob"]?>"
        <td contenteditable="true" data-old_value="<?= $doctors["hours"]?>"
        onBlur="saveInlineEdit(this,'hours','<?= $doctors["id"]?>')"><?=$doctors["hours"]?></td>

<?php endforeach ?>


And this is php file to update data:

CS50::("UPDATE doctors SET ".$_REQUEST["column"]."='".$_REQUEST["value"]."' WHERE  id='".$_REQUEST["id"]."'");
echo "saved";

Thanks for help!

1 Answer 1


Oh... I've missed "query" in CS50::query. Works!

  • That wasn't a thank you. That was the question author closing the question with an answer, which I assume she will accept in a day or two. Granted, it was a short answer, but it is accurate. ;-)
    – Cliff B
    Commented Aug 5, 2017 at 1:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .