yahoo5000 yahoo5000 - 6 months ago 10
MySQL Question

query doesnt work multi cols update

hello i am trying to update my database ones user leaves , and i want insert all user data : hare is my script :

$stmt = $connect->prepare("UPDATE users SET (
userid,
username,
usertype,
email,
level,
exp,
money,
ninjarank,
avatar,
village,
clan,
guild,
healthpoint,
chakrapoint,
ninjutsu,
taijutsu,
genjutsu,
senjutsu,
talent,
chakra,
health,
chakracontrol
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) WHERE userid= ?");
$stmt->bind_param("isisiiisssssiiiiiiiiiii",
$userid,
$username,
$usertype,
$email,
$level,
$exp,
$money,
$ninjarank,
$avatar,
$village,
$clan,
$guild,
$healthpoint,
$chakrapoint,
$ninjutsu,
$taijutsu,
$genjutsu,
$senjutsu,
$talent,
$chakra,
$health,
$chakracontrol,
$userid
);
$stmt->execute();
$stmt->close();
$connect->close();


but this query doesnt work get no result at all , i am set one of the valued +1000 just to make sure that query runs successfully but the value in database are the same please help with this query

Answer

That's an INSERT and not UPDATE syntax, use this format:

UPDATE users u
SET u.username = ?,
    u.OtherColumn = ?,
    ......
WHERE u.user_id = ?

Or, if you actually want to insert, then replace UPDATE with INSERT and delete the WHERE clause.

Comments