在我的情况下,我做了 INSERT 和 UPDATE 因为我做了一个条件,如果选民已经投票,它只会更新他在我的 tbl_initialVote 表上的信息。否则,它将插入。我怎样才能以更新格式做到这一点。请帮助...只是忽略变量$voter .. thnks的冗余。
$mysqli->query("INSERT INTO `tbl_initialVote` (`studId`, `candId`)
VALUES ('".$voter."', '".$chairman."'),
('".$voter."', '".$vchairman."'),
('".$voter."', '".$secretary."'),
('".$voter."', '".$treasurer."')")
到彼得姆
//this $getinfo is base on the logged in user
$getinfo = $mysqli->query("SELECT studId FROM`tbl_initialVote` WHERE studID = '".$voter."'");
if ($getinfo->num_rows > 0 ){
//here i know it got me error on this but this just i want to happen, make an update in the table if the user is already listed on my table. how could i suppose to do like this...@Peterm.
$mysqli->query(UPDATE `tbl_initialVote` set candId = VALUES('".$chairman."', '".$vchairman."', '".$secretary."', '".$treasurer."')
} else {
$mysqli->query("INSERT INTO `tbl_initialVote` (`studId`, `candId`)
VALUES ('".$voter."', '".$chairman."'),
('".$voter."', '".$vchairman."'),
('".$voter."', '".$secretary."'),
('".$voter."', '".$treasurer."')")
}