Kevin Kevin - 2 months ago 7
MySQL Question

PDO having issues when updating

I have an issue with PDO updating to my database, only certain variables will update and the others won't. The only ones that won't work are the "PvP" variables. I can't see any errors with PDO so I have absolutely no idea whats going on here. The "$epa_array" etc.. is just an array with int values parsed from json_decode.

I have verified that the mysql columns are in fact of type INT and the corresponding PDO query is also INT.

$u_id = 1;
$gw2_name = $epa_array[0]['name'];
$gw2_world_id = $epa_array[0]['world'];
$gw2_world_name = $epw_array[0]['name'];
$PvP_rank = $pvp_array[0]['pvp_rank'];
$PvP_total_wins = $pvp_array[0]['aggregate']['wins'];
$PvP_total_losses = $pvp_array[0]['aggregate']['losses'];
$PvP_rank_points = $pvp_array[0]['pvp_rank_points'];

$stmt = $db->prepare("UPDATE `Members` SET gw2_name = ?, WorldID = ?, Worldname = ?, PvP_rank = ?, PvP_total_wins = ?,PvP_total_losses = ?, PvP_rank_points = ?, WHERE ID = ?");
$stmt->bindValue(1, $gw2_name, PDO::PARAM_STR);
$stmt->bindValue(2, $gw2_world_id, PDO::PARAM_INT);
$stmt->bindValue(3, $gw2_world_name, PDO::PARAM_STR);
$stmt->bindValue(4, $PvP_rank, PDO::PARAM_INT);
$stmt->bindValue(5, $PvP_total_wins, PDO::PARAM_INT);
$stmt->bindValue(6, $PvP_total_losses, PDO::PARAM_INT);
$stmt->bindValue(7, $PvP_rank_points, PDO::PARAM_INT);
$stmt->bindValue(8, $u_id, PDO::PARAM_INT);
$stmt->execute();

Answer

might not be the only issue - but you do not need the last comma before the WHERE clause - it should be :

 ....PvP_rank_points = ? WHERE ID = ?");