0

I have a query that is supposed to be inserting data into a MySQL date field.

The incoming data is formatted as 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. The issue is that when I go to insert it into the field it always returns 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')
3
  • What does your INSERT statement look like? Commented Oct 16, 2014 at 1:26
  • 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') Commented Oct 16, 2014 at 1:29
  • 1
    you're using %d for the birthdate field. should be %s Commented Oct 16, 2014 at 1:30

1 Answer 1

1

Count your fields backwards in the values assignments. You're using %d for the birthdate field, which means expect a digit. Change that to %s for string and you should be ok.

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.