Part of the EllisLab Network
   
 
Sql Insert Help
Posted: 05 January 2009 03:31 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  31
Joined  10-24-2008

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:

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:

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?

Profile
 
 
Posted: 05 January 2009 10:00 PM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  31
Joined  10-24-2008

A little help guys? Please?

Profile
 
 
Posted: 05 January 2009 10:11 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  282
Joined  06-11-2007

how would that work anyway?

now, if you did this:

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

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

Profile
 
 
Posted: 05 January 2009 10:20 PM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  31
Joined  10-24-2008

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…

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120538 Total Logged-in Users: 28
Total Topics: 126598 Total Anonymous Users: 1
Total Replies: 665559 Total Guests: 370
Total Posts: 792157    
Members ( View Memberlist )
Newest Members:  kreessweeper240andrew nsuntroprachel123Rach123Glenn StavaImfaelSMS!persanul