2012-01-24 67 views
0
$idgen = uniqid(rand(), false); 
$churchName = $this->input->post('church_name'); 
$streetAddress = $this->input->post('street_address'); 
$locationalCity = $this->input->post('locational_city'); 
$locationalState = $this->input->post('locational_state'); 
$locationalZip = $this->input->post('locational_zip'); 
$locationalCountry = $this->input->post('locational_country'); 
$taxNum = $this->input->post('tax_exemption_number');** 

$this->db->query("INSERT INTO church_repo (church_name, street_address, locational_address, locational_zip, locational_country, locational_city, overseer_account_id, tax_exemption_number, status) VALUES('{$churchName}', '{$streetAddress}', '{$locationalCity}', '{$idgen}', '{$locationalState}', '{$locationalZip}', '{$locationalCountry}', '{$taxNum}', 'pending')"); 

上面的代碼沒有被正確插入,在詞,我發現了以下錯誤:笨不能正確插入SQL數據

Error Number: 1054

Unknown column 'locational_address' in 'field list'

INSERT INTO church_repo (church_name, street_address, locational_address, locational_zip, locational_country, locational_city, overseer_account_id, tax_exemption_number, status) VALUES('bgtg', 'ff', 'rgfr', '270284f1eec6e5bfd4', 'rgrd', 'bdtbdt', 'United States of America', '84894894894', 'pending')

Filename: C:\Workspace\htdocs\Jan-2012\Gospel-links.org\system\database\DB_driver.php

Line Number: 330

回答

2

的錯誤是不言自明的:沒有「locational_address」領域,如已經指出的d2byrke,所以你應該先檢查一下。

可能是「street_address」,也許?

作爲一個附錄,你是不是逃脫你在你的數據庫中輸入的值;使用查詢綁定,如果你不希望使用活動記錄:

$churchName = $this->input->post('church_name'); 
$streetAddress = $this->input->post('street_address'); 
$locationalCity = $this->input->post('locational_city'); 
$locationalState = $this->input->post('locational_state'); 
$locationalZip = $this->input->post('locational_zip'); 
$locationalCountry = $this->input->post('locational_country'); 
$taxNum = $this->input->post('tax_exemption_number'); 

$sql = "INSERT INTO church_repo(church_name, street_address, locational_address, locational_zip, locational_country, locational_city, overseer_account_id, tax_exemption_number, status) VALUES(?,?,?,?,?,?,?,?,?)"; 

$this->db->query($sql, array($churchName,$streetAddress,$locationalCity,$locationalState,$locationalZip,$locationalChurch,$taxnum,'pending'); 

或者,更清潔(和保護)與活動記錄:

$field['church_name'] = $this->input->post('church_name'); 
    $field['street_address'] = $this->input->post('street_address'); 
    $field['locational_city'] = $this->input->post('locational_city'); 
    $field['locational_state'] = $this->input->post('locational_state'); 
    $field['locational_zip'] = $this->input->post('locational_zip'); 
    $field['locational_country'] = $this->input->post('locational_country'); 
    $field['tax_exemption_num'] = $this->input->post('tax_exemption_number'); 
    $field['status'] = 'pending'; 
    $field['overseer_account_id'] = 'value here'; 

    $this->db->insert('church_repo', $field); 

哪裏$field是表名作爲數組索引和字段值作爲值。

+0

'street_address'是不存在的..謝謝你。順便說一句,你怎麼知道這是'street_address'? –

+0

@MichaelGrigsby你分配的變量看起來像你的表cols($ churchName,$ locationalCity ..)相同的名稱(camelCased),這是一個「找到差異」的遊戲:) –

3

檢查表屬性名稱,該錯誤意味着「locational_address 「不存在於你的表格中。可能只是一個錯字

0

試試這只是改變了順序或插入與列馬赫

$idgen = uniqid(rand(), false); 
$churchName = $this->input->post('church_name'); 
$streetAddress = $this->input->post('street_address'); 
$locationalCity = $this->input->post('locational_city'); 
$locationalState = $this->input->post('locational_state'); 
$locationalZip = $this->input->post('locational_zip'); 
$locationalCountry = $this->input->post('locational_country'); 
$taxNum = $this->input->post('tax_exemption_number');** 

$this->db->query("INSERT INTO church_repo (church_name, street_address, locational_address, locational_zip, locational_country, locational_city, overseer_account_id, tax_exemption_number, status) VALUES('{$churchName}', '{$streetAddress}', '{$locationalCity}', '{$locationalZip}', '{$locationalState}', '{$locationalCountry}', '{$idgen}', '{$taxNum}', 'pending')"); 
0

您需要清理/轉義您要插入的內容。如果有'或其他的東西你會遇到一個錯誤。確保你的數據庫確實包含locational_address。複製/粘貼以確保沒有錯別字。

我會考慮改變這一點,閱讀和遵循發生的事情要容易得多。然後數據正確轉義。

$data = array(
    'church_name' => $this->input->post('church_name'), 
    'street_address' => $this->input->post('street_address'), 
    ..... 
    'tax_exemption_number' => $this->input->post('tax_exemption_number') 
); 

$this->db->insert('church_repo', $data); 
+0

好吧很酷。其實我試圖弄清楚如何排列發佈數據但找不到任何東西。感謝您的提示。 –