0
|
1 <?php
|
|
2
|
|
3 // Basic example of PHP script to handle with jQuery-Tabledit plug-in.
|
|
4 // Note that is just an example. Should take precautions such as filtering the input data.
|
|
5
|
|
6 header('Content-Type: application/json');
|
|
7
|
|
8 $input = filter_input_array(INPUT_POST);
|
|
9
|
|
10 $mysqli = new mysqli('localhost', 'user', 'password', 'database');
|
|
11
|
|
12 if (mysqli_connect_errno()) {
|
|
13 echo json_encode(array('mysqli' => 'Failed to connect to MySQL: ' . mysqli_connect_error()));
|
|
14 exit;
|
|
15 }
|
|
16
|
|
17 if ($input['action'] === 'edit') {
|
|
18 $mysqli->query("UPDATE users SET username='" . $input['username'] . "', email='" . $input['email'] . "', avatar='" . $input['avatar'] . "' WHERE id='" . $input['id'] . "'");
|
|
19 } else if ($input['action'] === 'delete') {
|
|
20 $mysqli->query("UPDATE users SET deleted=1 WHERE id='" . $input['id'] . "'");
|
|
21 } else if ($input['action'] === 'restore') {
|
|
22 $mysqli->query("UPDATE users SET deleted=0 WHERE id='" . $input['id'] . "'");
|
|
23 }
|
|
24
|
|
25 mysqli_close($mysqli);
|
|
26
|
|
27 echo json_encode($input);
|