Re: [PHP-DB] MySQL Date insert
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:[EMAIL PROTECTED] Sent: Monday, July 28, 2003 2:17 PM To: [EMAIL PROTECTED] 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() . ""); 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. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Date insert
Budelak wrote: 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. d-m-Y is not the MySQL format for a date, though, so that means you're saving the date in a VARCHAR or CHAR column. You lose the benifits of all the date and time functions built into MySQL when you do that. Not a good method... either store the dates as Unix timestamps or MySQL timestamps. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Date insert
John, thanks, now I feel stupid, it's always the silly little things that get you. You were right, when I added the date to the existing insert I forgot to put the ending parentheses back in. Thanks for the help. Andrew. At 11:26 AM 7/28/2003, CPT John W. Holmes wrote: From: "Andrew D. Luebke" <[EMAIL PROTECTED]> > $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() . ""); > > 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. Like someone else said, using Date as a column name probably isn't very smart. Your problem is caused by not having a closing parenthesis in your query, though. '$date')") ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Date insert
From: "NIPP, SCOTT V (SBCSI)" <[EMAIL PROTECTED]> > I actually think I know part of this answer... I don't think you > need to define a variable to insert into your "date" field. Inserting an > empty value into this filed will populate the field in the database with the > current time, which it appears from your code is what you are trying to do > here. Try changing the field name and give that a shot. I think I am > actually right here though. Well, kind of. :) This will only happen if the column is a TIMESTAMP column. It does not work that way for DATE, TIME, or DATETIME columns. But... we're getting off-topic. :) ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Date insert
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".date('l F d Y')."\n"; Michele Petrovsky - Original Message - From: "Andrew D. Luebke" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> 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() . ""); > > 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. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Date insert
i have a feeling oyu're not getting a mysql error but a PHP error??? you have an odd number of parentheses and mysql_error will not have an closing paren. if that is the case, try this 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() . ""); "Andrew D. Luebke" <[EMAIL PROTECTED]To: [EMAIL PROTECTED] hetres.com> cc: Subject: [PHP-DB] MySQL Date insert 07/28/2003 02:16 PM 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() . ""); 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. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MySQL Date insert
I actually think I know part of this answer... I don't think you need to define a variable to insert into your "date" field. Inserting an empty value into this filed will populate the field in the database with the current time, which it appears from your code is what you are trying to do here. Try changing the field name and give that a shot. I think I am actually right here though. Scott -Original Message- From: Hutchins, Richard [mailto:[EMAIL PROTECTED] Sent: Monday, July 28, 2003 1:19 PM To: [EMAIL PROTECTED] Subject: RE: [PHP-DB] MySQL Date insert 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:[EMAIL PROTECTED] > Sent: Monday, July 28, 2003 2:17 PM > To: [EMAIL PROTECTED] > 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() . > ""); > > 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. > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Date insert
From: "Andrew D. Luebke" <[EMAIL PROTECTED]> > $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() . ""); > > 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. Like someone else said, using Date as a column name probably isn't very smart. Your problem is caused by not having a closing parenthesis in your query, though. '$date')") ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MySQL Date insert
Nope, changed the insert to: $result = mysql_query("INSERT INTO Boats (Make, Model, Serial, Stock, Extension, Cust_Name, Store, Insert_Date) VALUES ('$make', '$model', '$serial', '$stock', '$extension', '$name', '$store', '$date'") or die("Invalid query: " . mysql_error() . ""); with corresponding alter of the table of course, same error. Andrew. At 11:19 AM 7/28/2003, Hutchins, Richard 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:[EMAIL PROTECTED] > Sent: Monday, July 28, 2003 2:17 PM > To: [EMAIL PROTECTED] > 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() . > ""); > > 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. > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MySQL Date insert
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:[EMAIL PROTECTED] > Sent: Monday, July 28, 2003 2:17 PM > To: [EMAIL PROTECTED] > 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() . > ""); > > 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. > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php