This code shows a table's records via JavaScript using a JsGrid file and can edit or delete by AJAX.
This is my topic How can I load rows in JsGrid table that got from php file?, The problem I am not sure the data is secure during inserting and loading or not?
Is it really secure?
The names of PHP files are: newsConf, controll and getnewscat
HTML file: basic.html
in controll.php:
public function newsConfig(){ $this->CONN = new Conn();//class from external page to connect DB try{
$dfnet = $this->CONN->open_connect();
$qnco = mysqli_query($dfnet,"select * from category");
if(!$qnco) return "";
else{
while($qncoarray = mysqli_fetch_assoc($qnco)){
//here I try copy rows into array
$nnopCo[] = array(
'ID' => $qncoarray['ID'],
'Name' => $qncoarray['Name']
);
}
return $nnopCo;
}
$this->CONN->close_connect($dfnet); } catch(Exception $er){ }
in getnewscat.php:
<?php require_once "../../bin/controll.php";
$db_controll = new Controll();
$cat_news = new ArrayObject($db_controll->newsConfig());
header('Content-type: application/json');
echo json_encode($cat_news->getArrayCopy());
?>
in basic.html: is the same file from jsgrid demo, but I change the code in JavaScript and canceled the db.js file
<script>
$(function() {
{
$("#jsGrid").jsGrid({
height: "70%",
width: "50%",//100%
selecting: false,
filtering: false,
editing: false,
sorting: false,
paging: true,
autoload: true,
pageSize: 15,
pageButtonCount: 5,
controller: {
loadData: function(filter) {
return $.ajax({url: "../bin/getnewscat.php",data:filter
});
}
},
fields: [
{ name: "ID", type: "number", width: 50 },
{ name: "Name", type: "text", width: 50},
{ type: "control", modeSwitchButton: false, deleteButton: false }
]
});
$(".config-panel input[type=checkbox]").on("click", function() {
var $cb = $(this);
$("#jsGrid").jsGrid("option", $cb.attr("id"), $cb.is(":checked"));
});
});
</script>
In newsConf.php: that file should call basic.html and give the result by using an iframe:
<iframe name="demo" src="jsgrid-1.2.0/demos/basic.html"></iframe>