簡體   English   中英

查詢結果在數據庫中獲取0

[英]Getting 0 in database as result of query

大家好,所有新手:)不知道這是不是正確的標題,如果不能,對不起...

我正在嘗試為合適的用戶將數據從一個表輸入到另一個表

控制器:

function Admin(){
    $user = $this->input->post('username'); //there is one text field in view page were you input username
    $this->user->getEmail($user);
    if($this->user->getUser($user)){
        $this->user->Input_Admin();
        $this->Success();
    }
    $this->Fail();
}

模型:

function Input_Admin(){
    $k = array(
        'Name' => $this->input->post('username'),
        'Email' => $this->input->post('Email'),
    );  
    $a = $this->db->insert('admin', $k);

    return $a;
}

function getEmail($user){
    $this->db->select('Email');
    $this->db->where('username', $user);
    $q = $this->db->get('users');
    if($q->num_rows > 0){
        return $q->result();
    }
    return FALSE;
}

管理表ID,名稱,電子郵件中有3個字段...名稱函數的工作原理像一個超級按鈕,但對於電子郵件始終輸入0 ....所以我在做什么錯?

根據要求,這里是視圖:

<form name="info" method="post" action="<?php echo base_url(); ?>index.php/user_controler/admin">
    <table width="500" border="0" cellspacing="1" cellpadding="1" align="center" bgcolor="#FFCC99">
            <tr> 
                <td width="25%">Username:</td>
                <td><input type="text" name="username" size="30"></td>

            </tr>
            <tr> 
                <td colspan="6"> 
                    <div align="center"> 
                        <input type="submit" name="Confirm" value="Confirm">
                        <input type="reset" name="Cancel" value="CANCEL">
                    </div>
                </td>
            </tr>
    </table>
    </form>

<input type="text" name="Email" size="30">哪里?

你沒有在HTML中,所以你得到0值

將其放在html中,因此發布請求也會向您的控制器發送電子郵件;)

只是為了清楚:

$k = array(
        'Name' => $this->input->post('username'), //needs <input name="username"/> in html
        'Email' => $this->input->post('Email'), //needs <input name="Email"/> in html
    );  

另一個提示使用此:

<?php echo site_url('user_controller/admin'); ?>

代替

<?php echo base_url(); ?>index.php/user_controler/admin

更舒適,易於閱讀;)

如果要從數據庫發送用戶電子郵件,則可以嘗試以下操作:

function Admin(){
    $user = $this->input->post('username'); //there is one text field in view page were you input username
    $results = $this->user->getEmail($user);
    if($this->user->getUser($user)){
        $this->user->Input_Admin($results);
        $this->Success();
    }
    $this->Fail();
}
function Input_Admin($data){
    $k = array(
        'Name' => $this->input->post('username'),
        'Email' => $data->email,
    );  
    $a = $this->db->insert('admin', $k);

    return $a;
}

function getEmail($user){
    $this->db->select('Email');
    $this->db->where('username', $user);
    $q = $this->db->get('users');
    if($q->num_rows > 0){
        return $q->row();
    }
    return FALSE;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM