0

こんにちは、すべての初心者:) これが正しいタイトルかどうかわからないので、そうでない場合は申し訳ありません...

適切なユーザーのために、あるテーブルから別のテーブルにデータを入力しようとしています

コントローラ:

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

admin テーブルには id、name、email の 3 つのフィールドがあります。

必要に応じて、ビューは次のとおりです。

<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>
4

1 に答える 1

0

はどこ<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
    );  

もう1つのヒントはこれを使用します:

<?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;
}
于 2013-05-25T16:29:32.993 に答える