简体   繁体   English

PHP MySQL日期不起作用

[英]PHP MySQL dates not working

I have a query that is supposed to be inserting data into a MySQL date field. 我有一个查询,应该将数据插入到MySQL日期字段中。

The incoming data is formatted as MM/DD/YYYY. 传入数据的格式为MM / DD / YYYY。 I run it through this function: 我通过以下功能运行它:

$birthday = date("Y-m-d",strtotime($data[16]));

When I use var_dump to see what it looks like it, return YYYY-MM-DD which is correct. 当我使用var_dump查看外观时,返回正确的YYYY-MM-DD。 The issue is that when I go to insert it into the field it always returns 0000-00-00. 问题是,当我将其插入到字段中时,它总是返回0000-00-00。 What gives? 是什么赋予了?

The insert code: 插入代码:

INSERT INTO customers (email_address, confirm_email_address, 
full_name, phone_number, status,time, company, industry,fax, 
alternate_email_address, address, address2, city, state, zip_code, 
country, birthdate, repid, salesrep, secId) VALUES('%s','%s','%s','%s','%s',
UNIX_TIMESTAMP(),'%s','1','%s','%s','%s','%s',‌​'%s','%s','%s',
'USA','%d','%d','%d','%d')

Count your fields backwards in the values assignments. 在值分配中倒数您的字段。 You're using %d for the birthdate field, which means expect a digit. 您将%d用于生日日期字段,这意味着需要一个数字。 Change that to %s for string and you should be ok. 将其更改为%s以获取字符串,您应该可以。

INSERT INTO customers (email_address, confirm_email_address, 
full_name, phone_number, status,time, company, industry,fax, 
alternate_email_address, address, address2, city, state, zip_code, 
country, birthdate, repid, salesrep, secId) VALUES('%s','%s','%s','%s','%s',
UNIX_TIMESTAMP(),'%s','1','%s','%s','%s','%s',‌​'%s','%s','%s',
'USA','%s','%d','%d','%d')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM