Re: MySQL Date insert
| From: | michele.petrovsky | Date: | Mon, 28 Jul 2003 18:31:38 +0000 |
| Subject: | Re: MySQL Date insert | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-29524@lists.php.net to get a copy of this message | ||
Andrew, try this:
$date = date('Y m d H i s');
A similar syntax (with single quotes rather than double, and without
intervening dashes) has worked for me in some MySQL-related PHP code I've
just written. My code looked like this:
$title2 = "\n<h3 align=\"center\">".date('l F d
Y')."\n</h3>";
Michele Petrovsky
----- Original Message -----
From: "Andrew D. Luebke" <andrew@copeandmcphetres.com>
To: <php-db@lists.php.net>
Sent: Monday, July 28, 2003 2:16 PM
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.