I'm trying to learn how to create editable tables with jquery.tabledit.min.js but I'm really not aware of where my judgments are failing.
My table "testC" is:
id fisrt last
1 juan a
2 pedro b
3 diago c
and my index that I am trying to make work (to edit later and add information about my project):
$conn = sqlsrv_connect( $server, $connectionInfo );
//mi conecion a BD esta esta en sql server sqlsrv
$query = "SELECT * FROM testC ORDER BY id DESC";
$result = sqlsrv_query($conn, $query);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="jquery.tabledit.min.js"></script>
//las librerias , tengo ya en mi carpeta el documento con jquery
<table id="editable_table" class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
while($row = sqlsrv_fetch_array($result)){
echo '
<tr>
<td>'.$row["id"].'</td>
<td>'.$row["fisrt"].'</td>
<td>'.$row["last"].'</td>
</tr>
';
}?>
</tbody>
</table>
//la tabla anote mal first y puse fisrt pero lo e dejado asi por cuestiones de
//ser una tabla test
<script>
$(document).ready(function(){
$('#editable_table').Tabledit({
url:'action.php',
columns:{
identifier:[0, "id"],
editable:[[1, 'fisrt'], [2, 'last']]
},
restoreButton:false,
onSuccess:function(data, textStatus, jqXHR)
{
if(data.action == 'edit')
{
$('#'+data.id).remove();
}
}
});
});
</script>
and this is my code action.php:
$conn = sqlsrv_connect( $server, $connectionInfo );
$input = filter_input_array(INPUT_POST);
$query = "SELECT * FROM testC WHERE fisrt=? AND last=?";
$parameters = [$_POST["fisrt"], $_POST["last"]];
$result = sqlsrv_query($conn, $query, $parameters);
if($input["action"] === 'edit')
{
$query_edit = "UPDATE testC
SET fisrt = '$first_name',
last = '$last_name'
WHERE id = '$input["id"]'";
sqlsrv_query($conn, $query);
}
if($input["action"] === 'delete')
{
$query_del = "DELETE FROM testC WHERE id = '".$input["id"]."'";sqlsrv_query($conn, $query);
sqlsrv_query($conn, $query_del);
}
echo json_encode($input);
?>
currently shows the information of my database and table but when sending an edit it deletes the fields. what would be the problem?