I am making a form for updating the data in the database, but it is throwing me this error Catchable fatal error: Object of class mysqli_result could not be converted to string on line 73
I have tried outputting all the data and all are printing but not updating in the database.
Please give some suggestion, how to solve it?
$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");
}
}
</div>
make SQL with: email = '.$email.'
. You've better print the SQL string and execute in MySQL CMD or PHPMyAdmin to find out.
I have managed to solve the issue. I have added quotes for string values.
$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");
}
}
</div>