Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting datetime to put it in MySQL database??

Status
Not open for further replies.

atom267

Technical User
Mar 3, 2004
5
0
0
GB
Hi i know this is a very basic problem but i cant find a way to solve it. Have been through this forum too and dont find anything.
So I've got a form in my html page, and one of the fields (hidden) contains the following:

<input name="datetime" type="hidden" id="datetime" value="<?php echo(date("Y-m-j H:i:s"))?>">

I process the form through php and i try to send a query to mysql server in order to store that date. In my database, i have a field called datetime, type datetime.

$insertSQL = sprintf("INSERT INTO comment (name, text, datetime) VALUES (%s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['who'], "text"),
GetSQLValueString($HTTP_POST_VARS['what'], "text"),
GetSQLValueString($HTTP_POST_VARS['datetime'], "datetime"));

This is what i get from the server:

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 '04:39:20)' at line 1

I have tried lots of things but cant find why the format is wrong.

Does anyone know what to do please?
 
problem solved.
i had forgotten this

case "datetime":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;

...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top