CodeIgniter Forums
Sql Insert Help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Sql Insert Help (/showthread.php?tid=14516)



Sql Insert Help - El Forum - 01-05-2009

[eluser]draconus[/eluser]
I am in need of a little assistance with an sql insert. I start with processing a validated form and call the model and function I set up for this insert. So far so good, I even echoed out the post array to ensure that the model is getting the data it needs. From there I do the insert, which does create a new row in my table, but does not pass the form data in. here is my model code that I created for this:
Code:
function insert_user(){
        $this->input->post('firstName');
        $this->input->post('lastName');
        $this->input->post('username');
        $this->input->post('password');
        $this->input->post('email');
        

        $this->db->insert('users', $this);
    }

And to test that the model has the information it needs, I used the following line of code at the beginning of the insert_user function:
Code:
echo $this->input->post('firstName');

Which displays the data on screen correctly.

What could I be doing wrong that it is inserting an empty record into the table and not filling in the form fields? I thought originally that the trim on the form_validation may be the likely culprit, but if i can echo out the post data correctly from the model, then this couldn't be the case, correct?


Sql Insert Help - El Forum - 01-05-2009

[eluser]draconus[/eluser]
A little help guys? Please?


Sql Insert Help - El Forum - 01-05-2009

[eluser]ray73864[/eluser]
how would that work anyway?

now, if you did this:

Code:
$data = array(
               'firstName'=>$this->input->post('firstName'),
               'lastName'=>$this->input->post('lastName'),
               'username'=>$this->input->post('username'),
               'password'=>$this->input->post('password'),
               'email'=>$this->input->post('email')
        );

$this->db->insert('users', $data);

Another way that would work if i recall correctly:

Code:
$this->db->insert('users',$_POST);

The way you are doing it though, is to insert $this into the DB, unfortunately that is an object not an array.


Sql Insert Help - El Forum - 01-05-2009

[eluser]draconus[/eluser]
Oh, crap, your right... lol, thanks Smile That did the trick... I don't know how I didn't see that until you pointed it out... Seriously... thanks...