Afghan Host
Afghan Host

Reputation: 250

Current timestamp field in mysql table is not updated automatically

I really apologize for asking such a simple question but i am stuck in it. Actually my table has three coloumns such as id, status and date. The date field is current timestamp (Also I have selected on update current timestamp in phpmyadmin).

What I want is that date field should be updated on each update but it is not. Here is my code;

if($_POST['status']=="Expired")
    {
        $_POST['remaining']=0;
    }
    if($this->db->update('user_package',$_POST,array('upid'=>$_POST['upid'])))
    {
        redirect('package/view_admin_package_pending');
    }
    else
    {
        echo "Hey I could not update the User's requested Package. I am in Package Controller on line number 406";
    }

On update the date field updated as 00000000 instead of correct time and date.So, Can any one help me find out the solution.

NOTE: I have also tried doing bellow but did not work;

$_POST['date']=now();

also tried

$_POST['date']=time();

Upvotes: 1

Views: 3165

Answers (5)

Shahidul Islam Molla
Shahidul Islam Molla

Reputation: 640

function is enough for this code.

$data = array(
               'content_header' => $_POST['content_header'],
                'content_body' => $_POST['content_body'],
                'content_footer' => $_POST['content_footer'],
                'post_catagory' => $_POST['post_catagory']
                'update_time' => date('Y-m-d H:i:s')
        );

Upvotes: 2

user576126
user576126

Reputation:

$_POST['date'] = date('Y-m-d H:i:s', strtotime('23.12.2013 15:23:23'));

Upvotes: 0

Bandydan
Bandydan

Reputation: 631

Try not to use $_POST. Codeigniter provides useful way to get $_POST variables:

$my_update = array();
$my_update['status'] = $this->input->post('status');//in controller

... add there all your variables from the form in the same way ... After you will decide to update your table, set all the variables you need

$data = array(
  'status' => $my_update['status'],
  //...
);

To set your where condition, better use codeigniter tool: $this->db->where('upid', $my_update['upid']); After that, add a date field update: $this->db->set('created', 'now()'); And then you can update your table:

$this->db->update('user_package', $my_update);

Upvotes: 0

Afghan Host
Afghan Host

Reputation: 250

Actually there was problem in my projects. Theoretically and logically, Current timestamp (specially on update timestamp selected) automatically updates the date field to current timestamp. So, My code was right but I have confusion in my projects. Anyhow, I appreciate every one's Answer. Thank you

Upvotes: 0

juergen d
juergen d

Reputation: 204904

You can do that in SQL directly like this

update your_table
set some_column = 1,
    `date` = current_timestamp
where ...

Upvotes: 1

Related Questions