Welcome Guest, Not a member yet? Register   Sign In
Ajax and Data Insert Error
#1

[eluser]Unknown[/eluser]
Hi all,

I am new to CodeIgniter. I recently experienced a 1054 Database error when using using form_remote_tag to submit a form. It tells me there is a unknown column '_'.

The steps to reproduce this error are as follows:

Step 1: Build a function which includes $this->db->insert('sitereview', $_POST) within controller.
Step 2: In view file, establish form by using following code:

echo $this->ajax->form_remote_tag(array('url'=>'/review/review_insert', 'loading'=>"Element.show('indicator')", 'complete'=>"Element.hide('indicator')",'update'=>'reviewSubmitForm'));
echo form_hidden('siteID',$this->uri->segment(3));
echo form_hidden('dateAdded',mdate($datestring, $time));
echo form_hidden('authorID',1);

Step 3: I review all my form and am very sure there is no input field which I name after '_'

Step 4: Once I submit a from, I got error message

A Database Error Occurred
Error Number: 1054

Unknown column '_' in 'field list'

INSERT INTO `sitereview` (`siteID`, `dateAdded`, `authorID`, `reviewDetails`, `siteRating`, `_`) VALUES ('2', '2008-08-09 04:46:01', '1', 'sdf', '0', '')

Expected behavior:
I expect the form should go through.

Actual behavior:
The page throw an error and I have no idea where `_` comes from.

Note:
Systems I am using. PHP5. Apache 2.2. IE 7 and Firefox 2.0.0.16

Any help will be very much appreciated.

Kevin
#2

[eluser]valarkin[/eluser]
hello newCodeIgntor, welcome to the forums!

Ok, a few things to cover here. You may wish to use the [ code ] [/ code] tags to better display what is code from your explanation. What it looks like to me is that you are making use of the raw $_POST variable and it has an extra field in it. This might be added by the form_remote_tag function. I am not sure because I have never used the ajax features yet. What I would suggest is doing some basic validation on the inputs and making use of the built in CI input library. You can access safe POST data through $this->input->post('fieldname'); If for some reason you don't wish to do all of that, as a work around you could simply unset($_POST['_']); to remove it from the array.




Theme © iAndrew 2016 - Forum software by © MyBB