Question

I try to use x-editable but i can't find a way to update my database with new data.

In my index.php i have :

<a href="#" id="username">superuser</a>

and in main.js i have :

$('#username').editable({
type: 'text',
pk: 1,
url: 'post.php',
title: 'Enter username'

and in post.php :

 $pk = $_POST['pk'];
$name = $_POST['name'];
$value = $_POST['value'];

and after :

          $result = mysql_query('update users set '.mysql_escape_string($name).'="'.mysql_escape_string($value).'" where user_id = "'.mysql_escape_string($pk).'"');

When i try, nothing happen, no change in DB, no message, just nothing. If i change $value = $_POST['value']; and others with real values and i launch post.php directly, sql works.

Was it helpful?

Solution

JS

(function(){
         $('a#editlang').editable({
         url: 'post.php',
         escape: false,
         "mode": 'inline',
         "rows": '5',
         "inputclass": 'input-xxlarge',
         validate: function(value) {
            if($.trim(value) == '') {
                return 'This field is required';
            }
          },              
      });  

   });

HTML

<a name="editlang" id="editlang" data-type="textarea" data-pk="1" title="Edit">superuser</a>

in php

$pk = $_POST['pk']; // register id
$value = $_POST['value']; // new name

query:

$result = mysql_query('update users set name = "'.mysql_escape_string($value).'" where user_id = "'.mysql_escape_string($pk).'"');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top