Welcome Guest, Not a member yet? Register   Sign In
Using $_POST to submit?
#1

[eluser]Solarpitch[/eluser]
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.

Code:
$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...

Code:
$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'),

               );
              
        $this->report_model->insert_client($data);

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?
#2

[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.
#3

[eluser]Solarpitch[/eluser]
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
#4

[eluser]TheFuzzy0ne[/eluser]
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
#5

[eluser]simshaun[/eluser]
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.)
#6

[eluser]Solarpitch[/eluser]
I agree... thanks lads. I'll use the long method and make sure the data is safely inserted.

Cheers.
#7

[eluser]Mortred[/eluser]
simple.

Code:
unset($_POST['submit']);

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




Theme © iAndrew 2016 - Forum software by © MyBB