PHP PDO statement - Invalid parameter number

I’ve taken a SQL statement that worked for me in one place of the script and moved it to another place in the script, changing the parameters and statement but I get the error that I have an invalid parameter number. I just can’t see what I’m doing wrong. I counted the parameters and they match the number in the statement. Any help would be greatly appreciated!

Working:

$data = [
	'online' 			=> '0',
	'leavetime'			=> $rightnow,
	'timeadded'			=> $timeadded,
	'server_id' 		=> $server_id,
];
$sql = "UPDATE fivemin_players SET online=:online, leavetime=:leavetime, lifetime=lifetime+:timeadded WHERE online=1 AND server_id=:server_id";
$stmt= $pdo1->prepare($sql);
$stmt->execute($data);

Invalid parameter number:

/* No issue with sanity checks.  time to update the server in the DB. */
	$data = [
	'name' 			=> $server_name,
	'safename'		=> $server_safename,
	'host'			=> $server_host,
	'port' 			=> $server_port,
	'dbhost'		=> $server_dbhost,
	'dbname'		=> $server_dbname,
	'dbuser'		=> $server_dbuser,
	'dbpass'		=> $server_dbpass,
	'framework'		=> $server_framework,
];
$sql = "UPDATE fivemin_servers SET name=:name, safename=:safename, host=:host, port=:port, dbhost=:dbhost, dbname=:dbname, dbuser=:dbuser, dbpass=:dbpass, framework=:framework WHERE id=:server_id";
$stmt= $pdo1->prepare($sql);
$stmt->execute($data);

Should you have a comma at the end there?

Ten parameters, nine values.

3 Likes

Trailing comma’s are fine in arrays, and also in function calls as of PHP 7.3

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.