2012-01-24 3 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')"); 

コードは、CIに、私は次のエラーを取得しています、正しく挿入されていないSQLデータを挿入しない:CodeIgniterのが適切上記

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

エラーは自明である列でマッハするインサートだけ誤植

+0

'street_address'は存在しませんでした。ありがとうございました。とにかくそれは 'street_address'だったとあなたはどのように知っていたのですか? –

+0

@MichaelGrigsbyテーブルcols($ churchName、$ locationalCity ..)と同じ名前(camelCased)を持つようにポストを割り当てた変数は、「相違点を見つける」というゲームでした:) –

3

あなたのテーブルをチェックするには属性名、そのエラーは、「そのlocational_addressを意味し、 "あなたのテーブルには存在しません。これは単に順番を変えてみたり

$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」フィールドはありません、既にので、d2byrkeによって指摘あなたはそれをチェックすることから始めるべきです。

"street_address"、多分?

補足として、あなたのDBに入力する値をエスケープしません。 Active Recordのでさえクリーナー(および保護)

$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は、テーブル名として持つ配列がある

$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); 

インデックス、およびフィールド値を値として返します。

0

あなたが挿入しているコンテンツを墨塗り/エスケープする必要があります。もし何かがあるならば、あなたはエラーになるでしょう。あなたのDBに実際に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

大丈夫です。私は実際にポストデータをどのように配列するかを理解しようとしていましたが、何も見つかりませんでした。このチップをありがとう。 –