gznero gznero - 6 months ago 11
MySQL Question

(PHP, MYSQL) Update multiple rows with multiple WHERE

I'm new to PHP, now I face some strange issue about updating the value.

From these codes

for($i=0; $i < $count; $i++){

$sql = ("UPDATE applicant_skill SET App_skill_performance_score = '".$s_score[$i]."', App_skill_knowledge_score = ".$k_score[$i]."' WHERE App_Data_ID ='".$a_id."' && Position_ID = '".$p_id."' && Skill_ID = '".$skill_id[$i]."' ");


$resultt = "";

if ($conn->query($sql) == TRUE) {
$resultt = "FINISH";
} else {
$resultt = "ERROR";
}

}


At first I use INSERT and it works fine. Now I change to UPDATE but it updates nothing (the field is already in database waiting for update).

I don't know where mistake is, please help.

Answer

Try

$sscrore = $s_score[$i];
$kscore = $k_score[$i];
$aid = $a_id;
$pid = $p_id;
$skillid = $skill_id[$i];

 $sql = ("UPDATE applicant_skill SET App_skill_performance_score = '$sscrore', App_skill_knowledge_score = '$kscore'  WHERE App_Data_ID ='$aid'  AND Position_ID = '$pid'  AND Skill_ID = '$skillid' ");

Basically, you are missing one ' before ".$k_score[$i]."'

use AND instead of &&

Comments