Help Posting JEditable Data Back to Database

Help Posting JEditable Data Back to Database

thewebgentsthewebgents Posts: 7Questions: 0Answers: 0
edited April 2012 in General
I've added the script to make the 5th and 6th columns in my table editable to my page:

[code]

$(document).ready(function() {
/* Init DataTables */
var oTable = $('#example').dataTable();

/* Apply the jEditable handlers to the table */
$('td:eq(4), td:eq(5)', oTable.fnGetNodes()).editable( 'update_table_tenants.php', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
},
"submitdata": function ( value, settings ) {
return {
"row_id": this.parentNode.getAttribute('<?=$row['tenID']?>'),
"column": oTable.fnGetPosition( this )[2]
};
},
"height": "14px"
} );
} );

[/code]

My update_table_tenants.php file currently looks like this:

[code]
<?php
echo $_POST['value'].'*';
?>
[/code]

The table itself can be edited, and it adds a * to the new string / value entered.

The data however isn't updated in my database, and I presume this is because more info is required in the php file. Can anyone help me populate this?

Thanks
Dave

Replies

  • jfb1234jfb1234 Posts: 10Questions: 0Answers: 0
    Here is what mine looks like:

    <?php
    // UpDate.php
    $dsn = 'mysql:host=127.0.0.1;dbname=repairs;';
    $username = 'me';
    $password = '***********';
    $dbh = new PDO($dsn, $username, $password);
    // Update db based on col, value and id passed into $_POST from repairs.js
    if ($_POST['col'] == 'Tag Num') {
    $sql = "UPDATE items SET tag_num = " ."'". $_POST['value']."'" . " WHERE item_num = " . $_POST['id'];
    $dbh->exec($sql);
    echo $_POST['value'];
    } else if ($_POST['col'] == 'Enter Date') {
    $sql = "UPDATE items SET enter_date = " ."'". $_POST['value']."'" . "WHERE item_num = " . $_POST['id'];
    $dbh->exec($sql);
    echo $_POST['value'];
    } else if ($_POST['col'] == 'Due Date') {
    $sql = "UPDATE items SET due_date = " ."'". $_POST['value']."'" . "WHERE item_num = " . $_POST['id'];
    $dbh->exec($sql);
    echo $_POST['value'];
    } else if ($_POST['col'] == 'Done') {
    $sql = "UPDATE items SET done = " ."'". $_POST['value']."'" . "WHERE item_num = " . $_POST['id'];
    $dbh->exec($sql);
    echo $_POST['value'];
    } else if ($_POST['col'] == 'Description') {
    $sql = "UPDATE items SET description = " ."'". $_POST['value']."'" . "WHERE item_num = " . $_POST['id'];
    $dbh->exec($sql);
    echo $_POST['value'];
    } else if ($_POST['col'] == '') {
    echo 'You cannot change this column!!';
    }

    ?>
  • thewebgentsthewebgents Posts: 7Questions: 0Answers: 0
    Brillant jfb1234, thanks!
This discussion has been closed.