views:

82

answers:

2

I have just finished creating my signup form and now ready to insert data into the datebase using doctrine. Everything inserts fine but in my var_dump my birthday dropdown is in 3 seperates... day , month and year.. I would like to combine them and post as "birthday" into the db with doctrine.

I wish to do this in my controller, please take a look at my code and you'll see where I want to place this code.

My code:

public function submit() {

            $u = new User();
            $u->first_name = $this->input->post('first_name');
            $u->last_name = $this->input->post('first_name');
            $u->email = $this->input->post('email');
            $u->password = $this->input->post('password');
            //day
            //month
            //year
            $u->sex = $this->input->post('sex');
            $u->save();

            $this->load->view('submit_success'); // temporary account area page

}

}

A: 

After checking if the user has actually entered the full date, you can make a timestamp and then format it according to your db needs

$birthday = date("%d-%m-%Y", mktime(0, 0, 0, $this->input->post('month'), $this->input->post('day'), $this->input->post('year'));

Learn more on http://www.php.net/manual/en/function.date.php

gpasci
A: 

For those who come across this hurdle was the solution for me:

$u->birthday = $this->input->post('year') . '-' . $this->input->post('month') . '-' . $this->input->post('day'); 

This inserted what was selected in my form using the drop down date select into my db.

Psychonetics