我应该插入到partnerCode
单元格,其中用户输入的值等于randomfield
并且应该完全插入到相反的单元格,其中randomfield=partnerCode
例如:输入的值是 66666,它存在于randomfield
中并插入到相反的单元格中
ID randomfield partnerCode
+-------+-------------+-------------+
| 1 | 555555 | null |
+-------+-------------+-------------+
| 2 | 666666 | 666666 |
+-------+-------------+-------------+
| 3 | 777777 | null |
+-------+-------------+-------------+
网页表单代码:
<form name="Partner" action="../../pages/examples/profile.php" method="POST" >
<input class="random-but" name="partnerCode" value="<?php echo $partnerCode; ?>">
<input class="reload-but" type="submit" value=" >>>" name="partnerCode">
</form>
此处插入代码,但工作不正确
if (isset($_POST['partnerCode'])) {
// receive all input values from the form
$partnerCode= mysqli_real_escape_string($db, $_POST['partnerCode']);
$user_check_query = "SELECT * FROM refer WHERE partnerCode='$partnerCode' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if (count($errors) == 0) {
$query = "INSERT INTO refer (randomfield, partnerCode)
VALUES('$randomfield', '$partnerCode') where
randomfield='$partnerCode' ";
mysqli_query($db, $query);
}
而不是插入 你应该使用 更新
update refer
set partnerCode = '$partnerCode'
where randomfield='$partnerCode'
无论如何,您应该查看数据库驱动程序以获取预准备语句和绑定参数,而不是 SQL 和 mysqli_real_escape_string 中的 PHP var