Placid
Placid

Reputation: 1448

X-editable Bootstrap PHP database update

I am trying to update MySQL table with X-editable (Bootstrap). Problem is - the Database is not getting updated. I have gone through several similar kind of issue in stackoverflow and elsewhere. But couldn't find the solution.

My mysql database has a table named 'paving_variety' with the following three columns:

  1. id
  2. type
  3. publish

My front-end page has a table like the following:

    <?php
    $i = 1;
    foreach ($obj->showAllFromTable('paving_variety') as $variety) {
        extract($variety);
    ?>
        <tr>
            <td><?php echo $i++; ?></td>
            <td class="id"><?php echo $id; ?></td>
            <td><a href="#" class="xedit_variety" data-name="type" data-type="text" data-pk="<?php echo $id; ?>" data-url="post_variety_ajax.php"><?php echo $type; ?></a></td>
            <td ><button class="status_change btn btn-default"><?php echo $publish; ?></button></td>
        </tr>
    <?php
    }
    ?>

The javascript file has the following code:

    $(document).ready(function() {
        $('.xedit_variety').editable();
    });

The "post_variety_ajax.php" looks like this:

<?php
$pk = $_POST['pk'];
$name = $_POST['name'];
$value = $_POST['value'];

include 'adminclass.php';

if(!empty($value)) {
    $gar->updateVarietyName($name,$value,$pk);
} else {
    echo "This field is required!";
}
?>

The "adminclass.php" has the following code for updating the database:

public function updateVarietyName($name,$value,$pk) {
    $query = mysqli_query($this->conn,"UPDATE paving_variety SET $name='$value' WHERE id='$pk'");
}

Everything else seems ok, but the database is not getting updated. Anyone have any suggestions?

Thanks. Placid.

Upvotes: 2

Views: 5990

Answers (3)

Sudhanshu sharma
Sudhanshu sharma

Reputation: 1967

Or you can use $_REQUEST[] in post_variety_ajax.php file it will handle both get and post request.

I found a tutorial of x editable here :- jQuery X editable plugin

Upvotes: 0

&#214;mer An
&#214;mer An

Reputation: 664

Alternatively you can use,

$(document).ready(function() {
   $('.xedit_variety').editable({
      name: 'type',
      type: 'text',
      url: 'post_variety_ajax.php'
   });
});

where you should delete

data-name="type"
data-type="text"    
data-url="post_variety_ajax.php"

in your editable link.

Upvotes: 0

Placid
Placid

Reputation: 1448

Ok, I finally solved the problem. It is as follows:

$('.xedit_variety').editable({
    ajaxOptions : {
        type : 'post'
    }
});

Hope it helps someone else facing the same problem.

Upvotes: 3

Related Questions