Iam new on using Code Igniter. I want to use a custom insert query, reason is i want to use uuid() on my query and Im not sure what part of my code is wrong. I echoed the query, it seems that the custom query is correct, I tried it executing directly on my phpmyadmin. Please help me. TIA!
SSL.js
$('#btnSaveSSL').click(function(){
var SelMerch = $('#merchantList option:selected').val();
var SSLCert = $('#SSLCert').val();
var SSLPath = $('#file_SSL').val();
var ReqDate = $('#ReqDate').val();
var ExpDate = $('#ExpDate').val();
var Requester = $('#Requester').val();
$.ajax({
type:"post",
url: baseurl + "SSLController/AddSSLRecord",
data: {'SelMerch': SelMerch,
'SSLCert': SSLCert,
'SSLPath': SSLPath,
'ReqDate': ReqDate,
'ExpDate': ExpDate,
'Requester': Requester},
success:function(response)
{
alert(response);
},
error: function(response)
{
console.log(response.d);
}
});
});
SSLController.php
function AddSSLRecord(){
$SelMerch = $this->input->post('SelMerch');
$SSLCert = $this->input->post('SSLCert');
$SSLPath = $this->input->post('SSLPath');
$ReqDate = $this->input->post('ReqDate');
$ExpDate = $this->input->post('ExpDate');
$Requester = $this->input->post('Requester');
$sql = 'INSERT INTO tbl_user(SSLID,
MerchantID,
SSL_CertName,
SSL_CertPath,
RequestDate,
ExpirationDate,
Requester)
VALUES ( uuid()
,' .$this->db->escape($SelMerch).
','.$this->db->escape($SSLCert).
','.$this->db->escape($SSLPath).
','.$this->db->escape($ReqDate).
','.$this->db->escape($ExpDate).
','.$this->db->escape($Requester).')';
$this->SSLModel->CreateSSLRecord($sql);
// echo "success" . $sql;
}
SSLModel.php
public function __construct() {
parent::__construct();
$this->load->database();
}
function CreateSSLRecord($sql){
$this->db->insert("tbl_ssl", $sql);
}
2
Answers
If your custom query is correct and it is working fine so you may consider using this:
But don’t forget to sanitize your inputs before using this method.
Or you can use the Query Builder provided by Codeigniter: