2013-04-18 44 views
1
//here is my function block 
public function create_accnt() 
{ 
    $post = $this->input->post(); //gets all possible posts in array form 

    echo "Post array: ";print_r($post); // just to make sure that my array has values 

    $data = array(
     'userid' => $post['user_id'], 
     'lastname' => $post['lname'], 
     'firstname' => $post['fname'], 
     'username' => $post['username'], 
     'password' => $post['password'], 
     'usertype' => $post['user_type'], 
     'status' => 'A' 
    ); // assigning my values to their specific fields where they will be inserted 

    $query = $this->db->insert('accounts', $data); //insertion via active record 

    echo "<br/>Result of db last query: "; 
    echo $this->db->last_query();//to see how my query looks in code form 

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

//here is the result of the code above 

//Post array: Array ([user_id] => 123456 [lname] => Smith [fname] => John [username] =>  John [password] => password [c_password] => password [user_type] => S [btn_create] => Create) 

//Result of db last query: INSERT INTO accounts (userid, lastname, firstname, username, password, usertype, status) VALUES ('', '', '', '', '', '', '') 

這裏爲什麼查詢後我的VALUES都是空格?順便說一句,我使用CodeIgniter和我的數據庫驅動程序是PDO和我的數據庫是DBFoxPro。爲什麼我的INSERT語句的VALUES在執行後轉向了SPACES?

+1

因爲您的發佈數據中包含空間,所以您將節省空間在db..first檢查什麼是在帖子和你在db中保存什麼.. – saveATcode 2013-04-18 06:29:39

+0

@saveATcode仔細閱讀問題。 – 2013-04-18 06:30:30

+0

@YogeshSuthar:可能是我能夠得到問題,你能解釋他究竟在問什麼嗎? :) – saveATcode 2013-04-18 06:33:34

回答

1

我結束了使用CI的$this->db->query()功能和manualy提供我的查詢語句吧。我認爲$this->db->insert()不會在我的DB DBF-foxpro上通過PDO驅動程序工作。我也有一個關於$this->db->where()函數的問題。現在我只使用$this->db->query()。謝謝你的幫助。

0

代替

$data = array(
     'userid' => $post['user_id'], 
     'lastname' => $post['lname'], 
     'firstname' => $post['fname'], 
     'username' => $post['username'], 
     'password' => $post['password'], 
     'usertype' => $post['user_type'], 
     'status' => 'A' 
    ); 

使用

$data = array(
     'userid' => $this->input->post('user_id'), 
     'lastname' => $this->input->post('lname'), 
     'firstname' => $this->input->post('fname'), 
     'username' => $this->input->post('username'), 
     'password' => $this->input->post('password'), 
     'usertype' => $this->input->post('user_type'), 
     'status' => 'A' 
    ); 
+0

我試過了,但我得到了同樣的東西:( – 2013-04-18 06:58:57

相關問題