jquery-tabledit
jquery-tabledit copied to clipboard
Something is wrong somewhere
I have keenly followed the documention of your API but i cant simply seem to get this to either, update, delete or do anything. I have few questions ;
- Besides adding the Url to the location of the php script, is there any other thing i need to do to make sure the form data is submitted ?
2.how do i retrieve the data that is sent to the php script ?
this is my initialization file
$('#example9').Tabledit({`
url: 'example.php',
editmethod: 'post',
columns: {
identifier: [0, 'id'],
editable: [[1, 'make'],[2, 'year'],[3, 'model'],[4, 'platform']]
}
});
THIS IS MY HTML
<table class="table table-striped table-bordered" id="example9">
<thead>
<tr>
<th>#</th>
<th>Make</th>
<th>Model</th>
<th>Year</th>
<th>Platform</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>BMW</td>
<td>5-Series</td>
<td>2018</td>
<td>G30</td>
</tr>
</tbody></table>
//this is my php script
header('Content-Type: application/json');
// CHECK REQUEST METHOD
if ($_SERVER['REQUEST_METHOD']=='POST') {
$input = filter_input_array(INPUT_POST);
} else {
$input = filter_input_array(INPUT_GET);
}
// Connect to DB
$db = "nestor_acc";
$host = "127.0.0.1";
$user = "root";
$pass = "";
$con = mysqli_connect($host,$user,$pass,$db);
// Php question
if ($input['action'] === 'edit') {
$first = $input['make'];
$sql = "update students set first = '$first' where id = '1'";
$res = mysqli_query($con,$sql) or die(mysqli_error($con));
} else if ($input['action'] === 'delete') {
// PHP code for edit delete
} else if ($input['action'] === 'restore') {
// PHP code for edit restore
}
// RETURN OUTPUT
echo json_encode($input);
PLEASE WHAT AM I DOING WRONG
Hi,
- Besides adding the Url to the location of the php script, is there any other thing i need to do to make sure the form data is submitted ?
Load Tabledit and write url. If the data transfer to php script does not work, check the browser console.
- How do i retrieve the data that is sent to the php script
Tabledit script send data to php script. Php script have array $input
where are all data.
Repair a script that does not work
if ($input['action'] === 'edit') {
$sql = "update students set first = " . $input['make']. " where id = '1'";
$res = mysqli_query($con,$sql) or die(mysqli_error($con));
}
If the data transfer to php script does not work, check the browser console.
This is the message i get in my console
jquery.tabledit.js:287 Tabledit Ajax fail => parsererror : SyntaxError: Unexpected token < in JSON at position 0
This indicates that something on your site (the server, a plugin, or your theme) is returning extra HTML code at the beginning of the HTTP request response. This extra HTML code invalidates the JSON format of the actual content.
- Which version of Jquery you use?
- Check in console ... Network -> XHR -> select file and in right you have all ajax comunication. Check Respond.
Example
Thank you very much for your time, following your last direction, i realised i had an typo / error in my php script and i have corrected that, now the table row shows a green / success after hitting the edit, however the database is not updated as expected this are my codes (DB connection is in the required files)
require_once("../Functions/General.php");
require_once("../../Sys/init.inc.php");
header('Content-Type: application/json');
// CHECK REQUEST METHOD
if ($_SERVER['REQUEST_METHOD']=='POST') {
$input = filter_input_array(INPUT_POST);
} else {
$input = filter_input_array(INPUT_GET);
}
// Php question
if ($input['action'] === 'edit') {
$code = strtoupper(Validate(($input['code'])));
$id = Validate($input['id']);
$sql = "update nestor_glsourcecodes set glsourcecode_code = '$code' where glsourcecode_id = '$id'";
$res = mysqli_query($con,$sql) or die("Error 15i2");
$trail = Trail("General ledger source codes updated",$_SESSION['company']);
}
JS
$('#sourcecodes').Tabledit({
url: 'Assets/Scripts/glsourcecodes.php',
editmethod: 'post',
deleteButton: false,
columns: {
identifier: [0, 'id'],
editable: [[2, 'code']]
},
groupClass: 'btn-group btn-group-xs'
});
HTML
<table class="table table-striped table-bordered table-condensed" id="sourcecodes" width="50%">
<thead>
<tr style='background:#eee;'>
<th class="not-bold">Id</th>
<th class="not-bold">Module</th>
<th class="not-bold">Code</th>
</tr>
</thead>
<tbody>
<?php
$sourcecodes = ListSomething("nestor_glsourcecodes","nestor","glsourcecode_company = '$_SESSION[company]'");
$codecount = ListSomething("nestor_glsourcecodes","count","glsourcecode_company = '$_SESSION[company]'");
if($codecount > 0) {
$out = "";
foreach($sourcecodes as $sourcecode) {
$out .= "<tr>";
$out .= "<td>";
$out .= $sourcecode['glsourcecode_id'];
$out .= "</td>";
$out .= "<td>";
$out .= $sourcecode['glsourcecode_name'];
$out .= "</td>";
$out .= "<td>";
$out .= $sourcecode['glsourcecode_code'];
$out .= "</td>";
$out .= "</tr>" ;
}
echo $out;
//$out = "";
}
?>
</tbody>
</table>
I write tonight. I have work.
Alright, I will be waiting
@mankramo have you fixed the error?
@grim1365 Not yet, am still struggling to figure it out whiles i hope @BluesatKV comes to my assistance
This is the message i get in my console
jquery.tabledit.js:287 Tabledit Ajax fail => parsererror : SyntaxError: Unexpected token < in JSON at position 0
I got this error on windows today.
This is how I solved it.
Undefined Index in PHP is a Notice generated by the language. The simplest way to ignore such a notice is to ask PHP to stop generating such notices. You can either add a small line of code at the top of the PHP page or edit the field error_reporting in the php.ini file.
- Adding Code at the Top of the Page
A simple way to ask PHP to disable reporting of notices is to put a line of code at the beginning of the PHP page.
Code:
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
Or you can add the following code which stops all the error reporting,
<?php error_reporting(0); ?>