我正在尝试解决以下问题:在插入前将 插入前 列值partnerCode
和partnerCodeOwner1
与username
进行比较下表中,如果partnerCode and partnerCodeOwner1
的值与username
相同,则会出现错误消息,并且插入操作不应完成!
我的尝试低于但不正确!
$db = mysqli_connect('localhost', '*******', '********', '***********');
$user_check_query = "SELECT partnerCodeOwner1 FROM refer where randomfield='$partnerCode'";
$result = mysqli_query($db, $user_check_query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// --------------------HERE I'm trying to check for the same value in columns--------
//But incorrect! Syntax error?
if ($row) { // compare columns But incorrect
if ($row['username'] === ['partnerCodeOwner1']) {
array_push($errors, "U can't invest to yourself");
}
if(empty($row['partnerCodeOwner1'])) {
$query = "update refer
set partnerCodeOwner1= '" . $_SESSION['username'] . "'
where randomfield='$partnerCode' ;";
}else {
$query = "update refer
set partnerCode= '" . $_SESSION['username'] . "'
where randomfield='$partnerCode' ";
}
mysqli_query($db, $query);
}
?>
表中的示例
表: refer
ID randomfield username partnerCode partnerCodeOwner1
+-------+ ------------+-------------+-----------------+-----------+
| 1 | A45scdv | John | Not same | John |
+-------+-------------+-------------+-----------------+-----------+
| 2 | das654d | Alex | Alex | Not same |
+-------+-------------+-------------+-----------------+-----------+