1

codeigniterを使用してデータベースにデータを挿入しています。しかし、それは私に以下のエラーを与え続けます

Unknown column 'Array' in 'field list'</p><p>INSERT INTO `profile` (`loginid`, `name`, `email`, `gender`, `birthday`, `profilePhoto`, `date`) VALUES (Array, 'Zafar Khan', 'xafar@demo.com', 'male', '20.01.1987', '', '2012/11/19')

Filename: /Applications/XAMPP/xamppfiles/htdocs/membership_system/models/model_register.php</p><p>Line Number: 48

このエラーが発生するコードは次のとおりです

public function saveUserProfile() {
    $userId = $this->readUserId();

    $profile = array(
            'loginid'       => $userId,
            'name'          => $this->input->post('name'),
            'email'         => $this->input->post('email'),
            'gender'        => $this->input->post('gender'),
            'birthday'      => $this->input->post('birthday'),
            'profilePhoto'  => '',
            'date'          => date("Y/m/d")
        );

    $query = $this->db->insert('profile', $profile);

    if ($query) {
        return true;
    } else {
        return false;
    }
}

アップデート

これがreadUserId関数です

private function readUserId() {
    $this->db->select('id'); 
    $this->db->from('login');   
    $this->db->where('email', $this->input->post('email'));

    return $this->db->get()->result();
}

更新2

これがvar_dumpの出力です

array(1) {  [0]=>  object(stdClass)#18 (1) {    ["id"]=>    string(2) "14"  } }
4

4 に答える 4

4

の値は、列参照として扱われている値に$userId引用符で囲まれていない値が入力される結果になります。Array

于 2012-11-19T12:19:12.373 に答える
2

配列を$this->readUserId()返すようです。やってみreset($this->readUserId());ませんか?$profileを初期化する前に置いてください。

あるいは単に

echo var_dump( $this->readUserId() );

die();

..変数の内容を確認できるようにします。

==>編集:

$profileは次のようになる必要があります

$profile = array(
            'loginid'       => $userId['id'],
            'name'          => $this->input->post('name'),
            'email'         => $this->input->post('email'),
            'gender'        => $this->input->post('gender'),
            'birthday'      => $this->input->post('birthday'),
            'profilePhoto'  => '',
            'date'          => date("Y/m/d")
        );

==>編集2:

さて、あなたは追加することができます

$userId = $userId[0]->id;

$profile変数の初期化前。

于 2012-11-19T12:20:08.937 に答える
0

「userid」フィールドは配列です。あなたの投稿には別の「ユーザーID」が提出されています。ビューファイルで重複する名前を探します。

于 2012-11-19T12:20:13.727 に答える
0

問題は、スカラーの代わりに配列を返す$ this-> readUserId()にあるようです。これをチェックしてください。

于 2012-11-19T12:22:26.833 に答える