Postingan lainnya
Get Data dari database dengan ajax, Codeigniter
Untuk pengambilan data dari database, Table
price image name id
gmn saya ambil data diatas walau tidk menggunakan input form? mohon pencerahanya.
function addtocart($){
var price = $
var image = $
var name = $
var id = $
$.ajax({
type: "POST",
url: "<?php echo site_url('cart/add');?>",
data: "id="+id+"&image="+image+"&name="+name+"&price="+price,
success: function (response) {
$(".cartcount").text(response);
}
});
}
3 Jawaban:
<pre> public function Find($id , $image , $name , $price) { $dsn = $this->module->ConnectDataBase("root","",'test'); $db= $this->load->database($dsn, TRUE);
$connected = $pb_dbmaster-&gt;initialize();
if (!$connected) {
return false;
}
$db-&gt;where('image ', $image );
$db-&gt;where('name ', $name );
$db-&gt;where('price', $price);
$db-&gt;where('id', $id);
$data = $db-&gt;get('item')-&gt;result();
if (!$data) return false;
return $data;
} </pre>
<pre>
$id = $this->input->post('id'); $image = $this->input->post('image'); $name= ucwords($this->input->post('name')); $price= $this->input->post('price');
$respon = $this->ItemModel->Find($id , $image , $name , $price);
echo json_encode($respon); </pre>
<pre>
var id = $
var image = $
var name = $
var id = $
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "cart/add",
dataType: 'json',
data: {id: id , image: image, name: name, price: price},
success: function(respon) {
console.log(respon);
alert("Sukses Mencari data");
},
error: function(e){
alert("Terjadi kesalahan pada sistem");
}
});
</pre>
Jawaban Terpilih
Apakah aman bila menggunakan <pre> function($a,$b,$c){} </pre> Apakah dapat terhindari sql injection?
$a= $this->security->xss_clean($a); $b= $this->security->xss_clean($b); $c= $this->security->xss_clean($c);