我正在尝试解决以下问题:在插入前将 插入前 列值partnerCode
和partnerCodeOwner1
与username
进行比较下表中,如果partnerCode and partnerCodeOwner1
的值与username
相同,则会出现错误消息,并且插入操作不应完成!
比较时可能有问题吗?任何语法错误?
PHP 7.0版
我的尝试低于但不正确!
$user_check_query = "SELECT * FROM refer";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user['username'] === $user['partnerCodeOwner1']) {
array_push($errors, "You can't add item to yourself");
}
if ($user['username'] === $user['partnerCode']) {
array_push($errors, "You can't add item to yourself");
}
if (count($errors) ==0) {
//Start inserting
}
表中的示例
表: refer
ID randomfield username partnerCode partnerCodeOwner1
+-------+ ------------+-------------+-----------------+-----------+
| 1 | A45scdv | John | Not same | John |
+-------+-------------+-------------+-----------------+-----------+
| 2 | das654d | Alex | Alex | Not same |
+-------+-------------+-------------+-----------------+-----------+