這是我在CI中的第二個Web應用程序。Codeigniter模型不插入值
我想從表單中獲取單個值(在提交時)並將其插入到數據庫中。
我有一個控制器 「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{}
塊,但不輸入任何內容,到數據庫中。
我已經安裝配置/自動加載到自動加載數據庫LIB,如:
$autoload['libraries'] = array('database');
我在做什麼錯在這裏?
偉大的指出,我知道我做錯了什麼。傻我。謝謝@Cryptic! – CodeTalk