CodeIgniter not properly inserting sql data

$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

-------------Problems Reply------------

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.

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

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

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

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

Category:php Views:0 Time:2012-01-24

Related post

  • Show newly-inserted SQL data on main form 2012-02-03

    I’m having a little trouble figuring this one out. I’m fairly new to C#, but I feel like the answer to this should be simple. I have a form that displays data which it pulls from an SQL database. Users can open a new window and add new entries to the

  • What is the best way to fast insert SQL data and dependant rows? 2009-09-06

    I need to write some code to insert around 3 million rows of data. At the same time I need to insert the same number of companion rows. I.e. schema looks like this: Item - Id - Title Property - Id - FK_Item - Value My first attempt was something vagu

  • Inserting SQL Data into Linked (Foreign Key) Tables in SQLite 2010-10-22

    I have two tables linked by a foreign key. Example: "CREATE TABLE one (id INTEGER PRIMARY KEY, data REAL, time TEXT NOT NULL DEFAULT (datetime('now')));" "CREATE TABLE two (id INTEGER PRIMARY KEY, parent INTEGER, CONSTRAINT fc_two FOREIGN KEY (parent

  • How do I properly fetch SQL data from client after pageload 2011-01-03

    What I'm curious about, is I have a site (ASP.NET), which will display some search results. What I would like to do is load the page with search results, then have the client query my SQL database to check and see if any of the search results have be

  • Insert binary data into SQL Server using PHP 2009-03-27

    I have a varbinary(MAX) field in a SQL Server 2005 database. I'm trying to figure out how to insert binary data (ie. an image) into that field using PHP. I'm using ODBC for the connection to the SQL Server database. I have seen a number of examples t

  • Insert Only Date and Only time in the table using SQL Server 2005 2009-05-15

    How to Insert Only Date and Only time in the table(column datatype is DateTime) using SQL Server 2005. --------------Solutions------------- As far as I know, Date and Time are always stored together. The intern representation of it is a number, that

  • how to insert 61000 data objects into sql server 2005? 2009-07-08

    I am trying to insert 61,000+ objects, obtained via a remote call, into a SQL Server 2005 database in the fastest method possible. Any suggestions? I have looked at using SQLBulkCopy, but am having a few problems working out how to get the data into

  • whats the fastest way to insert streaming data into a table, DB is MS SQL server 2008 2009-07-22

    I've to write a c++ application that receives a huge data stream( many thousands of messages per second) and insert it into a MS sql server2008 db (into one or more tables) as fast as possible. I'm new to windows, and amongst so many ways described i

  • Insert xml data into sql tables 2009-11-16

    I have an xml document with the following format: <response username="123" customerName="CustomerName" siteName="SiteName" customerID="123" Period="2009"> <topics> <topic name="MyTopic"> <department name="MyDepartment" parent="Or

  • How to insert binary data into sql server using SSMS 2009-12-15

    Is there a way to insert binary data into sql server directly from SQL Server management studio? --------------Solutions------------- Try this: INSERT INTO Table (field1) VALUES (0xABCDEF) Where 0xABCDEF is your binary data represented as an hexadeci

  • Insert binary data into SQL from c# without a stored procedure 2009-12-23

    Does anyone know whether if its possible to insert binary data into an SQL field from c# without using a stored procedure? For example - convert a byte array into base64 or something like that and then use a text command like the following... String.

  • inserting only date in a column in sql server 2010-05-26

    Is there a way to insert only date in a datetime column in sql server without the time? for example date (datetime) =============== 12-01-2000 16-02-2000 or i should store this as a varchar and cast it when retriving so that i can convert to whatever

  • SQL Inserting multilingual data - loses diacritic marks etc 2010-07-14

    Inserting multilingual data into a SQL 2008 database (nvarchar field) I notice that it seems to lose some special character marks. e.g. INSERT INTO [dbName].[dbo].[tbl_Question_i18n] ([QuestionId] ,[LanguageId] ,[QuestionText]) VALUES (@lastinsertedq

  • how to insert current date and time to db using sql 2010-07-28

    I used the following code, but the DateTime field at sql is 2005-04-08 00:00:00 I want to have the time too. where should i change ... ... // Get the system date and time. java.util.Date utilDate = new Date(); // Convert it to java.sql.Date java.sql.

  • propel-gen insert-sql without losing data? 2010-10-29

    Is it possible to make propel-gen insert-sql without losing previous data? Is there any hack for this? I usually just add or remove some rows in a table editing schema.xml, executing: propel-gen propel-gen sql propel-gen insert-sql and this wipes out

  • Insert HTML data into the SQL Server 2011-04-13

    I have a problem about inserting HTML data into SQL Server. here are the details: this is my stored procedure; @articleID int, @articleBody nvarchar(max) AS UPDATE v2_Articles SET articleBody = @articleBody WHERE articleID = @articleID and this is my

  • Using foreach for insert gridview data into sql database 2011-05-31

    I have a client side gridview data and I want to insert gridview data to sql database . at first I import data from excel to gridview and now I want to insert it into sql database . I use foreach loop to insert records one by one . but foreach loop j

  • Insert Java.sql.Date into Derby Database 2011-07-20

    I am trying to insert a date object into the database but it says im trying to insert an Integer. Here is my code: public void insertAssignment(long studentId, String newAssignment, int ptsTotal, int ptsRecieved, String category, Date dueDate, String

  • SQL/ASP Insert/Update data 2011-08-05

    I have a SQL database table with User info - ID, Name, Address, City, State, Zip, Phone, Email. I display this data for the logged-in user on a web page - so only one user data will be displayed at a time. User will be able to INSERT & UPDATE dat

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.060 (s). 11 q(s)