为$ _ POST在codeigniter变空值 [英] Empty Value for $_POST variable in codeigniter
本文介绍了为$ _ POST在codeigniter变空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格:
< PHP
$ ATTR =阵列('身份证'=>'urlSubmit');
$ urlInputAttr =阵列(名称=>urlInput','价值'=>yourdomain.com,最大长度=> '50','大小'=> '25');
回声form_open('urlSubmission',$ ATTR);
回声form_input($ urlInputAttr);
#echo form_submit('urlInput','');
回声form_close();
?>
控制器叫** urlsubmission **
#确定是否域已经被抓取。
$这个 - >负载>模型('domaincheckmodel');
$这个 - > domaincheckmodel-> verifyduplicates();
和模型(domaincheckmodel),基本上检查重复记录,并插入一个新的领域中的一个函数:
函数verifyduplicates(){
urlInput的#$ _POSTed值
$ tldEntered = $这个 - >输入 - >后期('urlInput'); ##回声出$ _POSTed域输入。
##搜集如果域存在于数据库
$ DupDomains = $这个 - > DB-> get_where('ClientDomain',阵列('TLD'=> $ tldEntered)); //获取ClientDomain表
如果($ DupDomains-> NUM_ROWS()大于0){
$这个 - >负载>查看(ERR / domainexists'); ##域已使用
}
#否则,没有域present,插入。
其他{
#array插入值:
$ insertNewDomain =阵列('TLD'=> $ tldEntered);
$这个 - > DB->插入('ClientDomain',$ insertNewDomain);
$这个 - >负载>查看('成功/ domainfree'); ##域是免费的,尚未输入。
}
问题是:当我提交,其提交的记录到数据库,但 TLD
是空的。
解决方案
函数verifyduplicates(){
#prePARE数据
如果($这个 - >输入 - >后期('name_of_your_button')){
$ postedTLD = $这个 - >输入 - >后期('urlInput'); //获取unsanitized数据
回声$ postedTLD;
$这个 - > DB->集(TLD,$ postedTLD); //自动地通过AR逃脱
#INSERT数据
$这个 - > DB->插入('ClientDomain');
}
}
只是确保你有你的名字提交按钮
I have a form :
<?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();
and a function within a model(domaincheckmodel) which basically checks for duplicate records and inserts a new domain:
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.
}
Problem is: when I submit, it submits a record to the database but tld
is empty.
解决方案
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');
}
}
just make sure that you have name your submit button
这篇关于为$ _ POST在codeigniter变空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文