• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

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

Back
Top