ainoy31 Posted July 6, 2009 Share Posted July 6, 2009 I am reading data from a text file and then inserting it into a mysql table. Here is the code: $query = "INSERT INTO user_mail_list(userid, mail_date) VALUES ("; $fh = fopen("userid.txt", "r"); while(!feof($fh)) { $data = fgets($fh, 4096); $sql = $query . $data . ', 2009-06-30)'; mysql_query($sql); } It inserts into the table fine but the my mail date column has 0000:00:00 values rather than the 2009-06-30. I have echoed the query as well and it looks good. INSERT INTO user_mail_list(userid, mail_date) VALUES (5 , 2009-06-30) INSERT INTO user_mail_list(userid, mail_date) VALUES (184 , 2009-06-30) INSERT INTO user_mail_list(userid, mail_date) VALUES (469 , 2009-06-30) I am missing something stupid here. Thanks. AM Link to comment https://forums.phpfreaks.com/topic/164977-solved-insert-data-from-text-file/ Share on other sites More sharing options...
rhodesa Posted July 6, 2009 Share Posted July 6, 2009 dates need quotes around them: INSERT INTO user_mail_list(userid, mail_date) VALUES (5 , '2009-06-30') Link to comment https://forums.phpfreaks.com/topic/164977-solved-insert-data-from-text-file/#findComment-869935 Share on other sites More sharing options...
ainoy31 Posted July 6, 2009 Author Share Posted July 6, 2009 Thanks. Knew I miss something stupid. Later Link to comment https://forums.phpfreaks.com/topic/164977-solved-insert-data-from-text-file/#findComment-869942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.