我有一个表单,它从我的数据库中检索各种值并在表单中显示它。表单包含文本框,收音机,下拉菜单。检索部分工作正常,并为每个字段显示正确的值。但是当我想要更改字段并更新数据时,它不会更新。有人可以帮我这个。这是我的代码:
if(isset($_POST['submit'])){
$sql = "UPDATE tbl_dealer_info ";
$sql .= "SET phone = '$phone', email = '$email', sfid = '$sfid', ... WHERE id = '$idhidden' ";
$result = mysqli_query($conn, $sql);
if(!$result){
die('Could not update data: '. mysqli_error());
}
else{
echo "Updated Successfully";
}
}
<input type = "hidden" name = "idhidden" id = "idhidden" value = "" /> // My hidden input to store the id
显示&#34;已成功更新&#34;但实际上并没有更新。
答案 0 :(得分:0)
你缺少sql语句中的条件和';'
$sql = "UPDATE tbl_dealer_info ";
$sql .= "SET phone = '$phone', email = '$email', sfid = '$sfid' WHERE #here where condition #here ";
答案 1 :(得分:0)
试试这个
if(isset($_POST['submit'])){
$sql = "UPDATE tbl_dealer_info SET phone = '".$phone."', email = '".$email."', sfid = '".$sfid."', ... WHERE id = ".$idhidden;
$result = mysqli_query($conn, $sql);
if(!$result){
die('Could not update data: '. mysqli_error());
} else{
echo "Updated Successfully";
}
}