我正在制作一个用于更新数据库中数据的表单,但它给我发现了这个错误Catchable fatal error: Object of class mysqli_result could not be converted to string on line 73
我尝试输出所有数据,但都在打印,但没有在数据库中更新。
请提出一些建议,如何解决?
$id = $_GET['id'];
$t_id = $_GET['table_id'] - 2;
if(isset($_POST['submit'])){
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$gender = intval($_POST['gender']);
$treatment = intval($_POST['treatment']);
$source = intval($_POST['source']);
$status_ = intval($_POST['status']);
$remark = $_POST['remark'];
//below code is line 73
$leadUpdateSql = "UPDATE lead SET
name = $name
,phone = $phone
,email = $email
,gender_id = $gender
,treatment_id = $treatment
,source_id = $source
,status_id = $status
,remark = $remark
WHERE lead.id = $id";
if ($conn->query($leadUpdateSql) === TRUE) {
echo "Record updated successfully";
header("location:edit.php?id=$id&table_id=$t_id&updated=successfully");
}
}
答案 0 :(得分:1)
使用email = '.$email.'
制作SQL。您最好打印SQL字符串并在MySQL CMD或PHPMyAdmin中执行以查找。
答案 1 :(得分:0)
我设法解决了这个问题。我为字符串值添加了引号。
$id = $_GET['id'];
$t_id = $_GET['table_id'] - 2;
if(isset($_POST['submit'])){
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$gender = intval($_POST['gender']);
$treatment = intval($_POST['treatment']);
$source = intval($_POST['source']);
$status_ = intval($_POST['status']);
$remark = $_POST['remark'];
$leadUpdateSql = "UPDATE lead SET
name='$name' // here was the issue, now added quotes
,phone='$phone' // here was the issue
,email='$email' // here was the issue
,gender_id=$gender
,treatment_id=$treatment
,source_id=$source
,status_id=$status_
,remark='$remark' // here was the issue
WHERE lead.id=$id";
if ($conn->query($leadUpdateSql) === TRUE) {
header("location:index.php?updated=successfully&table_id=$table_id#$t_id");
}
else{
header("location:edit.php?id=$id&table_id=$t_id&error=unsuccess");
}
}