Re: MySQL Date insert

From: Date: Sun, 10 Aug 2003 08:53:23 +0000
Subject: Re: MySQL Date insert
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-29796@lists.php.net to get a copy of this message
This is how I implemented a similar though not exactly the same problem: $tempdate = gmdate("d-m-Y"); $insertSQL = sprintf("INSERT INTO gennews (newsdate, newsheadline, country, newsfull) VALUES ($tempdate, %s, %s, %s); So, you only have to change the format of the gmdate what you want. Bunmi Richard Hutchins wrote:
Don't know about your date format, but you have named your table column DATE which is a reserved keyword in MySQL. Try naming that something different and see if you still get the error.
-----Original Message----- From: Andrew D. Luebke [mailto:andrew@copeandmcphetres.com] Sent: Monday, July 28, 2003 2:17 PM To: php-db@lists.php.net Subject: [PHP-DB] MySQL Date insert Hello, I have the following PHP code:
        $date = date("Y-m-d H:i:s");
        $result = mysql_query("INSERT INTO Boats (Make, Model, Serial, Stock, Extension, Cust_Name, Store, Date) VALUES
                ('$make', '$model', '$serial', '$stock', '$extension', '$name', '$store', '$date'")
                or die("Invalid query: " . mysql_error() . "</body></html>");
The problem is with the Date column. It is of type DATETIME. I get an error on the second line of the insert statement. I assume I'm not putting formatting the date-time variable correctly but I've tried everything I can think of, so any help is very much appreciated. Thanks. Andrew.


« previous php.db (#29796) next »