Welcome Guest, Not a member yet? Register   Sign In
Inserting date into the database
#1

[eluser]mdcode[/eluser]
Yet another form question.

When a form is submitted, I am attempting to insert a date into the database using the CURDATE() parameter, however, it either fails to insert a row, inserts a 0, or just inputs CURDATE() into the field. I have also tried it with and without a hidden field in the form.

My VIEW:
Code:
<?php echo form_hidden('date_raised', 'CURDATE()'); ?>

CONTROLLER:
Code:
/* check if the form has been submitted */
if($this->input->post('submit_form'))
{
    $this->projects_model->insert();
}

And my MODEL:
Code:
/* inserting the project data */
        function insert()
        {
        $data = array(
            'customer'=>$this->input->post('customer', TRUE),
            'division'=>$this->input->post('division', TRUE),
            'date_raised'=>$this->input->post('date_raised', TRUE),
            'date_required'=>$this->input->post('date_required', TRUE),
            'tech'=>$this->input->post('tech', TRUE),
            'rep'=>$this->input->post('rep', TRUE),
            'priority'=>$this->input->post('priority', TRUE),
            'allocated_time'=>$this->input->post('allocated_time', TRUE),
            );
            
            $this->db->insert('projects',$data);
        }
Ihave also tried this in the model:
Code:
'date_raised'=>CURDATE(),
both with and without quotes surrounding the CURDATE() and within parentheses. This just brings up the error:
Code:
Fatal error: Call to undefined function curdate()
#2

[eluser]Mackstar[/eluser]
CURDATE() is an sql command, AR isn't keeping it as an SQL command it is trying to keep it as a string, or in your second case is even trying to use it as a php function. I would use 'date_raised'=>date('Y-m-d')

Cheers

Richard
#3

[eluser]mdcode[/eluser]
I've actually just found this same thing on the forums - that'll teach me for not trying multiple searches first, but thanks for your help, it works fine.




Theme © iAndrew 2016 - Forum software by © MyBB