2

This line is giving error: "Too few arguments". What is the problem?

$InsertQuery = sprintf("INSERT INTO listing (ldate, places, company, designation, projectdetails, desiredcandidate, hrname, hrcontact, email) VALUES (DATE_FORMAT(%s,'%Y %m %d),%s,%s,%s,%s,%s,%s,%s,%s)", $ldate,$places,$company,$designation, htmlentities($projectdetails), htmlentities($desiredcandidate),$hrname,$hrcontact,$email);
0

2 Answers 2

6

Well, your string specifies 12 placeholders and you only provide 9 values. The sprintf function requires that you pass as many values as the number of placeholders you specify in the format string. I actually think the error message is strikingly clear and is about as good an error message as you will ever see.

Sign up to request clarification or add additional context in comments.

6 Comments

Exactly the error is too clear. I am passing 9 arguments and their are 9 %s. Can you please clear where are 12 place holders?
You are forgetting about the %Y %m %d - those are placeholders as well.
Well, at least %d is - I am not sure whether or not PHP considers %Y and %m valid type specifiers.
But those are part of MySQL Data_Format function. I forgot to end with '. That makes it '%Y %m %d', but that is not solving my problem. Is it that sprintf considers everything that starts with % as a placeholder?
Escaping any % you want to output literally is a good idea, whether what follows is a legal type specifier or not. It may become one in the future.
|
5

The arguments are the expressions, and they should match in number the % format specifiers. If you really just need a % char, use %%.

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.