如何根据输入的ID将行更新为输入? 例如。 20,23,24更新'价格' 我的代码:
$result = mysqli_query($con,"UPDATE product SET price=price+(".$reduction."/1.23) WHERE id='".$id."'");
HTML
<form method="post">
<input name="reduction" type="text" >
<input name="id" type="text" value="id" > <input name="submit" value="ID" type="submit">
</form>
答案 0 :(得分:4)
您可以使用&#34; IN&#34;像这样的功能
$result = mysqli_query($con,"UPDATE product SET price=price+(".$reduction."/1.23) WHERE id in('".$id."')");
答案 1 :(得分:2)
您需要格式化查询,如下所示: -
<form method="post">
<input name="reduction" type="text" >
<input name="id" type="text" value="id" > <input name="submit" value="ID" type="submit">
</form>
<?php
if(isset($_POST) && !empty($_POST)){
$id= $_POST['id'];
$result = mysqli_query($conn,"UPDATE product SET price=price+(".$reduction."/1.23) WHERE id IN ('".$id."')"); // instead of = you have to use `IN`
}