php – Codeigniter模型不插入值
发布时间:2020-12-13 22:46:58 所属栏目:PHP教程 来源:网络整理
导读:这是我在CI中的第二个Web应用程序. 我试图从表单中获取单个值(提交时)并将其插入数据库. 我有一个控制器“urlsubmission”: ?phpclass Urlsubmission extends CI_Controller{ function index() { $this-load-model('domaincheckmodel'); $this-domaincheckm
这是我在CI中的第二个Web应用程序.
我试图从表单中获取单个值(提交时)并将其插入数据库. 我有一个控制器“urlsubmission”: <?php class Urlsubmission extends CI_Controller{ function index() { $this->load->model('domaincheckmodel'); $this->domaincheckmodel->verifyduplicates(); } } ?> 模型(domaincheckmodel) – 在数据库中搜索任何重复项: <?php class Domaincheckmodel extends CI_Model{ function __construct(){ // Call the Model constructor parent::__construct(); } function verifyduplicates(){ #PREPARE DATA $sql = "SELECT tld from ClientDomain WHERE tld = ?"; $postedTLD = $_POST['urlInput']; // Get unsanitized data $endquery = $this->db->query($sql,array($this->db->escape_str($postedTLD))); // Query db #CONDITION if($endquery->num_rows() > 0){ $this->load->view('err/domainexists'); ##domain already used ## please login.. } else{ #number of rows must be 0,insert into db $newDomain = "INSERT INTO ClientDomain(tld) VALUES('".$this->db->escape_str($postedTLD)."')"; $this->load->view('success/domainfree'); ## please register } } } ?> 现在有两个愚蠢的观点:domainexists和domainfree: domainexists: <h2>Domain Exists</h2> domainfree: <h2>Domain free</h2> 问题是:当我运行脚本时,没有错误,但它正在执行else {}阻止,但没有输入任何内容到数据库中. 我已经设置config / autoload来自动加载db lib,如: $autoload['libraries'] = array('database'); 我在这做错了什么? 解决方法
您没有运行SQL查询.做这个.
$newDomain = "INSERT INTO ClientDomain(tld) VALUES('".$this->db->escape_str($postedTLD)."')"; $this->db->query($newDomain); 或者你可以使用simple_query() $newDomain = "INSERT INTO ClientDomain(tld) VALUES('".$this->db->escape_str($postedTLD)."')"; $this->db->simple_query($newDomain); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |