gpt4 book ai didi

php - 如何插入……值……其中 Value= 等于用户给定的值?复杂查询

转载 作者:行者123 更新时间:2023-11-30 21:32:51 25 4
gpt4 key购买 nike

我应该插入到 partnerCode 单元格中,用户输入的值等于 randomfield 并且它应该正好插入到 opposite 单元格中randomfield=partnerCode

例如: 输入的值为66666 它存在于randomfield 并插入到相对的单元格

   ID      randomfield  partnerCode    
+-------+-------------+-------------+
| 1 | 555555 | null |
+-------+-------------+-------------+
| 2 | 666666 | 666666 |
+-------+-------------+-------------+
| 3 | 777777 | null |
+-------+-------------+-------------+

HTML 表单代码:

     <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 而不是插入

    update refer 
set partnerCode = '$partnerCode'
where randomfield='$partnerCode'

无论如何,而不是 sql 和 mysqli_real_escape_string 中的 php var 你应该看看你的 db 驱动程序的准备语句和绑定(bind)参数

关于php - 如何插入……值……其中 Value= 等于用户给定的值?复杂查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55363142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com