I'm trying to solve problem which will compare BEFORE INSERTING columns values partnerCode
and partnerCodeOwner1
with username
in the table below, If partnerCode and partnerCodeOwner1
values same with username
should error message And insert shouldn't be completed!
May be problem while comparing? Any syntax error??
PHP version 7.0
My attemp below but incorrect!
$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
}
Example in table
table: refer
ID randomfield username partnerCode partnerCodeOwner1
+-------+ ------------+-------------+-----------------+-----------+
| 1 | A45scdv | John | Not same | John |
+-------+-------------+-------------+-----------------+-----------+
| 2 | das654d | Alex | Alex | Not same |
+-------+-------------+-------------+-----------------+-----------+