我想用查询更新mysql表,但它显示
错误 - mysqli_query()期望参数3为长
if($money >= 400) {
$query = "UPDATE users SET spam = spam + 1, money = money - 400 WHERE user_id=".$_SESSION['user'];
$query = "UPDATE users SET score = score + 2500 WHERE user_id=".$_SESSION['user'];
$update = mysqli_query($conn,$query,$query);
echo 'Spam.exe Upgraded for $400!!';
} else {
// Prints error
echo 'Not enough Money!!';
}
答案 0 :(得分:2)
只需像这样单独调用2个查询:
if($money >= 400) {
$query1 = "UPDATE users SET spam = spam + 1, money = money - 400 WHERE user_id=".$_SESSION['user'];
$query2 = "UPDATE users SET score = score + 2500 WHERE user_id=".$_SESSION['user'];
$update1 = mysqli_query($conn,$query1); // call 1st query
$update2 = mysqli_query($conn,$query2); // call 2nd query
echo 'Spam.exe Upgraded for $400!!';
} else {
// Prints error
echo 'Not enough Money!!';
}
答案 1 :(得分:1)
只需使用 mysqli_multi_query() ,即可使用字符串连接将两个更新查询作为单个查询运行:
$query = "UPDATE users SET spam = spam + 1, money = money - 400 WHERE user_id=".$_SESSION['user'].";";
$query .= "UPDATE users SET score = score + 2500 WHERE user_id=".$_SESSION['user'];
mysqli_multi_query($con,$query);
答案 2 :(得分:0)
检查以下代码:
$query = "UPDATE users SET spam = spam + 1, money = money - 400 WHERE user_id=".$_SESSION['user'];
$query1 = "UPDATE users SET score = score + 2500 WHERE user_id=".$_SESSION['user'];
$update = mysqli_query($conn,$query);
$update1 = mysqli_query($conn,$query1);
echo 'Spam.exe Upgraded for $400!!';
答案 3 :(得分:-1)
mysqli_query
的第三个参数是$resultmode
。
请参阅http://php.net/manual/en/mysqli.query.php。
只需使用mysqli_query($conn,$query).