Welcome Guest, Not a member yet? Register   Sign In
Hidden Value Insert Problem
#1

[eluser]Zed[/eluser]
hi,
i want to insert current date into my db and the value comes from a hidden field in a form. i declared the date variable in my view file, all i got was 00:00:00 in the db, then i altered it and declared it in my controller file, but still didn't work
this is what i did:

view
Code:
$date = $date = date('Y-m-d H:i:s', now());
<?php echo form_hidden('date', '$date'); ?>

controller
Code:
$form_data = array(
'title' => set_value('title'),
'surname' => set_value('surname'),
'firstname' => set_value('firstname'),
'email' => set_value('email'),
'state' => set_value('state'),
'tel' => set_value('tel'),
'topic' => set_value('topic'),
'msg' => set_value('msg'),
'date' => set_value('date')
);
#2

[eluser]Matalina[/eluser]
Your view code is wrong. Remove the single quotes from $date;

Code:
$date = date('Y-m-d H:i:s', now());
echo form_hidden('date', $date);
#3

[eluser]Zed[/eluser]
[quote author="Matalina" date="1333036557"]Your view code is wrong. Remove the single quotes from $date;

Code:
$date = date('Y-m-d H:i:s', now());
echo form_hidden('date', $date);
[/quote]

thanks, but it still not inserting
#4

[eluser]Matalina[/eluser]
You don't need now() and I think that's the wrong function as well. If you want the current time you need to to time();

Now is only mysql function.

but just leaving it empty will make it the currrent time. Read the php docs.
#5

[eluser]Zed[/eluser]
[quote author="Matalina" date="1333050693"]You don't need now() and I think that's the wrong function as well. If you want the current time you need to to time();

Now is only mysql function.

but just leaving it empty will make it the currrent time. Read the php docs.[/quote]

thanks a great deal. I have removed the now, but its still the same. I feel the problem should be from the controller. I don't know if the controller is getting the date variable. I am going bald trying to figure this out. I've tried various approach all to no avail.
#6

[eluser]Zed[/eluser]
I discovered that the date hidden field in the view file is not passing to the controller. I used a name other than date to insert the value into my database but with hidden field, i found that the value is not entering. What could be the cause?
#7

[eluser]InsiteFX[/eluser]
WRONG! Now() is not only MySQL! Read the CodeIgniter Doc's!

CodeIgniter has it's own now() function in the date_helper!

CodeIgniter Users Guide -Date Helper
#8

[eluser]Zed[/eluser]
[quote author="InsiteFX" date="1333057612"]WRONG! Now() is not only MySQL! Read the CodeIgniter Doc's!

CodeIgniter has it's own now() function in the date_helper!

CodeIgniter Users Guide -Date Helper
[/quote]

yeah. have seen it. but the problem on ground is that my form is not passing a variable. its a hidden field with date as a value/name but I keep getting 000 on my db. tried several methods but to no avail, then I decided to use a name instead of date and it still was not entering my db so I came to conclusion that my form is not passing the hidden field variable to my controller. that brings me to why is it not passing?
thanks
#9

[eluser]boltsabre[/eluser]
Bug hunting time...

In your controller, try var_dump($_POST) and see what you're getting from your form (or var_dump($this->input->post());

But I'm at a complete loss as to why you want to pass the current date from your view, to your controller, then to your model - why not just set the date in your model SQL statement???
#10

[eluser]InsiteFX[/eluser]
And what is your database field type set to?

This is how I insert dates and times into my database field datetime
Code:
// --------------------------------------------------------------------

/**
  * add_post()
  *
  * Description:
  *
  * @access public
  * @return void
  */
public function add_post()
{
  $now = date("Y-m-d H:i:s");

  $data = array(
   'title'   => $this->input->post('title'),
   'tags'   => $this->input->post('tags'),
   'status'  => $this->input->post('status'),
   'body'   => $this->input->post('body'),
   'category_id' => $this->input->post('category_id'),
   'user_id'  => $this->session->userdata('user_id'),
   'pub_date'  => $now,
  );

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




Theme © iAndrew 2016 - Forum software by © MyBB