我有一张表格:
<?php
$attr = array('id'=>'urlSubmit');
$urlInputAttr = array('name'=>'urlInput','value'=>'yourdomain.com','maxlength'=>'50','size'=>'25');
echo form_open('urlSubmission',$attr);
echo form_input($urlInputAttr);
#echo form_submit('urlInput', '');
echo form_close();
?>
a controller called **urlsubmission**
# Determine whether domain already has been crawled.
$this->load->model('domaincheckmodel');
$this->domaincheckmodel->verifyduplicates();
和模型中的函数(domaincheckmodel),它基本上检查重复记录并插入新域:
function verifyduplicates(){
# $_POSTed value of urlInput
$tldEntered = $this->input->post('urlInput'); ## echo out $_POSTed domain entered.
## Gather if the domain exists in db
$DupDomains = $this->db->get_where('ClientDomain', array('tld'=>$tldEntered)); // Get ClientDomain table
if($DupDomains->num_rows() > 0 ){
$this->load->view('err/domainexists'); ##domain already used
}
# else, no domain present, insert.
else{
#array of insert values:
$insertNewDomain = array('tld'=>$tldEntered);
$this->db->insert('ClientDomain', $insertNewDomain);
$this->load->view('success/domainfree'); ##domain is free and has not been entered.
}
问题是:当我提交时,它会向数据库提交一条记录,但tld
为空。
答案 0 :(得分:0)
function verifyduplicates(){
#PREPARE DATA
if ($this->input->post('name_of_your_button')){
$postedTLD = $this->input->post('urlInput'); // Get unsanitized data
echo $postedTLD;
$this->db->set('tld', $postedTLD); // AutoMagically escaped by AR
#INSERT DATA
$this->db->insert('ClientDomain');
}
}
只需确保您的提交按钮名称为