• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using $_POST to submit?

Hey Guys,

I see in the tutorial video's you can submit a the whole post of a form to the database using this simple line.

$this->db->insert('comments', $_POST);

This doesnt seem to work for me because it's including the value of the submit button and all... and is trying to put that into the query. INSERT INTO...mysubmit...VALUES..('submit');

I have to use this as a work around which seem a little more than what is needed...

$data = array(
               'account' => $this->input->post('account'),
               'customer_name' => $this->input->post('customer_name'),
               'address1' => $this->input->post('address1'),
               'address2' => $this->input->post('address2'),
               'address3' => $this->input->post('address3'),
               'provence' => $this->input->post('provence'),
               'county' => $this->input->post('county'),
               'country' => $this->input->post('country'),
               'email' => $this->input->post('email'),
               'telephone' => $this->input->post('telephone'),
               'mobile' => $this->input->post('mobile'),
               'fax' => $this->input->post('fax'),
               'website' => $this->input->post('website'),
               'description' => $this->input->post('website'),


Is there something I'm missing with this? The one line using the $_POST seems alot easier and less code. Why is it including the value of the submit button also?

[eluser]Armchair Samurai[/eluser]
[quote author="Solarpitch" date="1234391341"]Why is it including the value of the submit button also?[/quote]
That's standard behavior - it has nothing to do with the framework.

If it really bothers you that much, just use unset() on the offending element before submitting the $_POST data.

Ah.... I wasnt aware you could unset it.. but makes sence considering it is an array. Cool.. ill try it later and see how I get on. It's just they dont unset it in the tutorial video and it magically works perfect. Do do do do Smile

I'd like to just remind you that inserting the post array into the database before sanitising it is can be very dangerous. Never sacrifice quality for less quantity. Smile

I don't want to jump the gun and call you lazy, but don't be lazy. ;-) Just use the long version and play it safe. (Don't forget to sanitize.)

I agree... thanks lads. I'll use the long method and make sure the data is safely inserted.




and then
$this->db->insert('mytable', $_POST);

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.