我正在更新两列,即visastatus和当前日期。当我只更新我的visastatus列时,它工作正常但是当我应用这个查询时,两个列都在更新,那么它使我的visastatus 0和当前日期也没有更新。我的查询有问题吗?
<?php if(isset($_POST['submit']))
{
echo $radio = $_POST['radio'];
$date_clicked = date('Y-m-d');
$sql = "UPDATE user SET visastatus='$radio' and
currentdate='$date_clicked' WHERE id='$id'"; //this my update query.
$query = mysqli_query($conn, $sql);
if($query)
{
echo "<h4 style='color:green'>Action Performed Successfully....
</h4>";
}
else
{
echo "<h4 style='color:red'>Failed.</h4>";
}
}
?>
<form method="POST" action="" enctype="multipart/form-data">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6" style="margin-top:
8px;" align="left">
<label class="checkbox-inline tourist-rad">
<input type="radio" name="radio" id="success" value="Successfull
done">Successfull
</label>
<label class="checkbox-inline tourist-rad">
<input type="radio" name="radio" id="decline" value="Visa
declined">Declined
</label>
</div>
<div class="form-group">
<button type="submit" name="submit" value="submit" class="btn
btn-primary" style="float: right;">Update Menu Item</button>
</div><br><br><br><br><br><br>
</body>
</html>
答案 0 :(得分:0)
试试这个。
UPDATE user SET visastatus=$radio,currentdate=$date_clicked WHERE id=$id
答案 1 :(得分:0)
SQL更新查询的语法是
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
在查询中使用,
代替AND
$sql = "UPDATE user SET visastatus='$radio', currentdate='$date_clicked' WHERE id='$id'";