Jump to content

Recommended Posts

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 :D

 

Dave

Link to comment
https://forums.phpfreaks.com/topic/260894-jeditable-send-data-back-to-database/
Share on other sites

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.

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

<?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.

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?

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.

[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());

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.