No announcement yet.

What's wrong with this insert?

  • Filter
  • Time
  • Show
Clear All
new posts

  • What's wrong with this insert?

    I'm new to scriptcase and new to php so I'm hoping this is something small. But my insert is failing and I can't seem to figure out why. Any help would be greatly appreciated!

    $what = 'Client Login';
    $when = date('Y-m-d H:i:s');
    $sqlins = "insert into client_activity_log (client_id, what, when) values ([user_logged_in], 'client login', '".$when."')";

    This is the error I get:

    Error while accessing the database:
    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 'when) values (4, 'client login', '2014-04-25 09:53:18')' at line 1


    Last edited by friscoted1125; 04-25-2014, 09:55 AM.

  • #2
    The $when is not within quotes. You might consider putting the whole string between double quotes:

    $sqlins = "insert into client_activity_log (client_id, what, when) values ([user_logged_in], 'client login', '$when')";

    If that doesn't work I think the date is not in the correct format for the database.

    Besides that, if you need to log the user-access then there's a default audit trail option in scriptcase you can activate. It will log all defined actions then, no programming needed, just a simple configuration.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development /