LainaaWarning: Missing argument 5 for smf_db_insert(), called in /home/a3789387/public_html/create_character.php on line 202 and defined in /home/a3789387/public_html/Sources/Subs-Db-mysql.php on line 592
I have no idea why it's giving me this error. The code is working fine. The code is basically designed to insert data into a table. (Character Creation System) The db_insert function that I'm using works but for some reason it's still giving me this error.
This is my code for the INSERT SQL.
$smcFunc['db_insert']('insert',
'{db_prefix}rpg_characters',
array(
'character_id' => 'string', 'member_name' => 'string', 'avatar' => 'string', 'f_name' => 'string', 'm_name' => 'string', 'l_name' => 'string', 'age' => 'string', 'gender' => 'string', 'race' => 'string', 'faction' => 'string', 'class' => 'string', 'job' => 'string',),
array (
$c_id, $username, $avatar, $fname, $mname, $lname, $age, $gender, $race, $faction, $class, $job,));
Let's read the error carefully ;):
Lainaus käyttäjältä: Jamora1124 - elokuu 06, 2013, 08:51:56 IP
LainaaWarning: Missing argument 5 for smf_db_insert()
So, not an SQL error, but a function error: missing argument.
$smcFunc['db_insert'] is a function, "missing argument" means that the function requires a certain number of arguments (5 in that case) and you are not providing "some" of them (the 5th in that case).
For more details on the function see: http://wiki.simplemachines.org/smf/Db_insert
Okay, I figured out what was missing. But I always thought the "keys" part was only for 'replace'? So you have to add the last array regardless it the method is insert, replace or ignore?
And it is used only by Postgre, though since you are calling a function that requires that argument you have to add *something*, it may even be an empty array if you know you don't need it. ;)
So it sounds like the documentation at least implies that the 5th argument should be optional (only needed in a few cases), but the code is written to require that argument. Perhaps someone familiar with the function can touch up the documentation's wording, or else the code to make it truly optional?
It's always a bit messy to deal with (and document) arguments that are needed only in some cases -- if you make them truly optional (from the PHP perspective), you've got to add additional code to check that they were given in those cases where they're needed (you need a default value which can't be confused for a legitimate value, such as a scalar -1 instead of an array). However, to make them mandatory for all uses is a nuisance (having to type in dummy argument values).