Should be trivial -- WTH?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Should be trivial -- WTH?

Post by alex.barylski »

EDIT | I think I may have just spotted the problem...missing closing ) affected another query of mine so maybe thats it.
I have this line of code:

Code: Select all

$sql = sprintf("INSERT INTO %sproofs VALUES(0, $puid, $time, '$proof', '$rawdata'", DB_PREFIX);
Simple right? Spot the error, cause I don't... :banghead:

Code: Select all

Warning: sprintf() [function.sprintf]: Too few arguments in /var/www/devine/core/functions.php on line 127
What am I missing, I frequently use this technique to construct SQL statements and I have never encountered this problem before...I'm quite irritated by this and I hope in my frustration I am missing something simple.
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Should be trivial -- WTH?

Post by Ziq »

This is a very simple error :)

If you try to add into database some values including '%s' you are getting this error. For example:

Code: Select all

 
define('DB_PREFIX', 'a_');
$proof = "it's your error %s";
$sql = sprintf("INSERT INTO %sproofs VALUES(0, $puid, $time, '$proof', '$rawdata'", DB_PREFIX);
echo $sql;
 
 
Post Reply