dvent Posted April 13, 2012 Share Posted April 13, 2012 Hi All, I have a table (with an ID of example) that can be seen here: http://tinyurl.com/cfla7wp The following script calls jeditable.js and makes the Telephone & Mobile columns editable. Once edited, the table shows the new value plus a * symbol. <script type="text/javascript"> $(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("1"), "column": oTable.fnGetPosition( this )[2] }; }, "height": "14px" } ); } ); </script> What I need to do however is add the value entered into my database, but I do not know how to do this. I believe I need to do something like: UPDATE my_table VALUE whatever column has been edited in the table WHERE tenID is the same as the row selected in the table i.e. if I update the MOBILE NUMBER of the person called BILL GATES it would find his tenID, update numMobile in the table called my_table All help appreciated Dave Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/ Share on other sites More sharing options...
MMDE Posted April 14, 2012 Share Posted April 14, 2012 Have you set up a MySQL server? Do you know how to connect to it? Do you know how to send the data to the server from a form for example? Do you want to it seamless in the background, or send it as for example POST data? If you do know the above, I'm surprised you don't know how to update it. mysql_query('UPDATE table SET column = value WHERE id = '.$id); Something like that. Remember to sanitize the input. Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337277 Share on other sites More sharing options...
dvent Posted April 14, 2012 Author Share Posted April 14, 2012 Have you set up a MySQL server? Do you know how to connect to it? Do you know how to send the data to the server from a form for example? Do you want to it seamless in the background, or send it as for example POST data? If you do know the above, I'm surprised you don't know how to update it. mysql_query('UPDATE table SET column = value WHERE id = '.$id); Something like that. Remember to sanitize the input. Yes I have a MySQL server, Yes I can connect to it and Yes I can send from a form. I have done those three things literally once though for a specific example, so tweaking and changing is what I need to do here - hence asking for help. I would like the data to go into the table in the background. Dave Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337279 Share on other sites More sharing options...
MMDE Posted April 14, 2012 Share Posted April 14, 2012 <?php if(!empty($_POST['test'])){ echo $_POST['test']; } ?> <form action="" method="post"> <input type="text" name="test" /> <input type="submit" name="submit" value="submit" /> </form> Test it, and play around with it. Is this something like what you want? I already told you the mysql query. Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337281 Share on other sites More sharing options...
dvent Posted April 15, 2012 Author Share Posted April 15, 2012 I've got this: mysql_query("UPDATE test SET $column = $value WHERE [tenID] = $id" ) or die(mysql_error()); But get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= value WHERE [tenID] =' at line 1 Thoughts please? Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337426 Share on other sites More sharing options...
MMDE Posted April 15, 2012 Share Posted April 15, 2012 I've got this: mysql_query("UPDATE test SET $column = $value WHERE [tenID] = $id" ) or die(mysql_error()); But get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= value WHERE [tenID] =' at line 1 Thoughts please? $query = "UPDATE test SET $column = $value WHERE [tenID] = $id"; echo $query; mysql_query($query) or die(mysql_error()); Correct me if I'm wrong: Also, [tenID]???? This doesn't really sound like a valid (or at least usual) column name in MySQL (the [ and the ] is what I'm reacting about). If you've done the same with the $column, then that might be the reason. Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337453 Share on other sites More sharing options...
dvent Posted April 15, 2012 Author Share Posted April 15, 2012 [tenID] is the name of my ID column in the test table. So basically what I'm trying to say it put the $value into the $column when the tenID is the same as the $id captured Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337536 Share on other sites More sharing options...
MMDE Posted April 15, 2012 Share Posted April 15, 2012 [tenID] is the name of my ID column in the test table. So basically what I'm trying to say it put the $value into the $column when the tenID is the same as the $id captured I just tested in my own database, if your table has a column named: [tenID] then you need to do this: '[tenID]' source: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html This might work: mysql_query("UPDATE test SET '$column' = '$value' WHERE '[tenID]' = $id" ) or die(mysql_error()); If not, try this, and tell us the exact message that appears on the screen: $query = "UPDATE test SET '$column' = '$value' WHERE '[tenID]' = $id"; echo $query; mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337541 Share on other sites More sharing options...
dvent Posted April 15, 2012 Author Share Posted April 15, 2012 UPDATE test SET '' = '' WHERE '[tenID]' = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' = '' WHERE '[tenID]' =' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337552 Share on other sites More sharing options...
MMDE Posted April 15, 2012 Share Posted April 15, 2012 UPDATE test SET '' = '' WHERE '[tenID]' = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' = '' WHERE '[tenID]' =' at line 1 Actually, sorry, you need to use this type ` ( http://en.wikipedia.org/wiki/Grave_accent ) around the '[tenID]. But that is not the error you now got. The error says that the $column and $value variables are not set or empty. Quote Link to comment https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/#findComment-1337553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.