0

我有一个表格:

       <?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为空。

4

1 回答 1

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'); 
    }
} 

只需确保您为提交按钮命名

于 2013-01-24T03:01:01.140 回答