How to store current dat in new row

Status
Not open for further replies.

bontemuis

Member
Hi there,

I've visited already many corners of this forum, but I really can't figure this out. Please look at my php script in a form (onAfterProcess):

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$right_now = date();
$user_key_1 = (int) $formModel->formData['user_id_raw'];
$user_key_2 = (int) '{registration___id_raw}';
$query->insert('table2')->set('reg_id = ' . (int) ($user_key_2))->set('reg_user = ' . (int) ($user_key_1))->set('date = ' . ($right_now));
$db->setQuery($query);
$db->execute();

It doesn't accept date(), because I get this error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4.

What goes wrong here?
 
Did you try to run the code?
"blue" doesn't indicate an error but a function (red a string, grey a comment...)
 
Yes, I did. But now I'm thinking this might have something to do, either with the format settings of the date element or maybe server settings. You have to know I'm based in the Netherlands and our common date format is d-m-Y. So now i've changed that back to Y-m-d and added an "s" for seconds in time format. However, I still get this error message: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '11:36:43' at line 4", so now I'm thinking: is this about a server setting UTC versus Local time?
Anyhow, should the date function parameters correspond with the format settings of the date element?
 
MySQL needs MySQL format, not a display format
but this syntax is wrong
set('date = ' . ($right_now));

You must use quotes (it needs a date string) not paranthesis.

Not relevant for your error but I think the format must be
$right_now = date("Y-m-d H:i:s"); (H = 24 hours, h = 12 hours)
 
Ok. First I tried '$right_now', than "$right_now", but no success. Maybe I misunderstood.
But then I tried set('date = ' . $db->quote($right_now)); and this worked! Is this the best way to do it?
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top