Php 正在数据库中获取0作为查询的结果

Php 正在数据库中获取0作为查询的结果,php,codeigniter,Php,Codeigniter,大家好,这里的新手:)不知道这是不是正确的标题,如果不是很抱歉 我试图为正确的用户从一个表到另一个表输入数据 控制器: 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->us

大家好,这里的新手:)不知道这是不是正确的标题,如果不是很抱歉

我试图为正确的用户从一个表到另一个表输入数据

控制器:

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个字段。。。name的功能工作得很好,但对于电子邮件,始终输入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>
哪里是

在html中没有,所以得到0值

将其放在html中,这样post请求也会向您的控制器发送电子邮件;)

我只想说清楚:

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

在表格中输入用户名有效,但对于电子邮件,它只输入0我不想从表格中输入电子邮件。。。当您输入所需用户的用户名时,函数应将电子邮件从一个表中取出,并与用户名一起放入另一个表中是,但此处$this->input->post('email')**您需要**$\u post['email']数据,如果不存在,您将得到0:)检查我更新的答案,不确定它是否能100%工作我想你需要检查是否一切正常,但逻辑现在似乎正常如果我这样做,我会遇到2个错误:遇到PHP错误严重性:注意消息:未定义属性:stdClass::$email Filename:models/user.PHP行号:101发生数据库错误错误错误号:1048列“email”不能为空在
admin
Name
Email
)中插入值('seve',NULL)文件名:C:\wamp\www\P-projekat\system\database\DB_driver.php行号:330但是如果我只输入'Email'=>$数据,并且在getEmail return true中,则在Email列中输入1,您必须自己调试,无论如何都要进行变量转储($results);$results=$this->user->getEmail($user),您可能需要检查数据库字段名,我不知道您的dbschema:P
<?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;
}