php - 使用插入查询 CI PHP Mysql Ajax
问题描述
我是使用 Code Igniter 的新手。我想使用自定义插入查询,原因是我想在我的查询中使用 uuid() 并且我不确定我的代码的哪一部分是错误的。我回应了查询,似乎自定义查询是正确的,我尝试直接在我的 phpmyadmin 上执行它。请帮我。蒂亚!
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);
}
解决方案
如果您的自定义查询是正确的并且工作正常,那么您可以考虑使用它:
$this->db->query($your_query);
但不要忘记在使用此方法之前清理您的输入。
推荐阅读
- python - “AssertionError: push() 期望移动是合法的”,显示一个不是传入的棋盘
- wordpress - 在 WordPress 网站上出现重复的 403 错误
- java - 如何在 Java 中创建单元测试?
- stored-procedures - 如何在 CosmosDb 事务中隔离读取后插入?
- c++ - 如何使用 C++ 中的函数计算出现在字符串中的字符类型?
- python - Visual Studio 无法识别 NuGet
- odata - Odata 查询过滤列表的第一个元素
- javascript - 当我添加 for() 函数时,其他函数在 JS 中不做任何事情
- swift - 是否可以使用 swiftUI 在 watchOS 上隐藏 Digital Crown 指示器
- javascript - 我安装了错误的 NPM 包。我应该担心吗?