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')");

The code above isn't inserting correctly, in Ci I'm getting the following error:

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

4 Answers 4

3

check your table attribute names, that error means that "locational_address" doesn't exist in your table. may be just a typo

Sign up to request clarification or add additional context in comments.

Comments

2

The error is self-explanatory: there's no "locational_address" field, as already pointed out by d2byrke, so you should start by checking that.

Might be "street_address", maybe?

As an addendum, you're not escaping the values you enter in your DB; use query bindings, if you don't want to use 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');

Or, even cleaner (and protected) with Active Record:

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

Where $field is an array with table names as index, and field values as value.

2 Comments

'street_address' was non-existent.. thanks man. and btw how'd you know it was 'street_address' anyhow?
@MichaelGrigsby the variables you assigned the post to look like having the same name (camelCased) of your table cols ($churchName,$locationalCity..), it was much a game of "spot the differences" :)
0

You need to be sanitizing/escaping that content you are inserting. If there is a ' or something else you'll hit an error. Make sure your DB really does contain locational_address. Copy/paste to make sure no typos.

I would consider changing to this, it's much easier to read and follow whats happening. And the data is properly escaped then.

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

1 Comment

Okay cool. I was actually trying to figure out how to array out post data but couldn't find anything. Thanks for this tip.
0

Try this just changed the order or insert to mach with column

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.