2017-06-03 64 views
-3

我想提出一个形式,在更新数据库中的数据,但它扔我这个错误Catchable fatal error: Object of class mysqli_result could not be converted to string on line 73开捕致命错误:类mysqli_result的对象不能转换为字符串上线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

了解准备语句以防止SQL injection.also周围字符字段的qoutes将设置自动 – Jens

+0

我没有看到你的代码任何可能会抛出异常。没有什么可以创建一个“mysqli_result类的对象”。 –

回答

1

使SQL有:email = '.$email.'。您最好打印SQL字符串并在MySQL CMD或PHPMyAdmin中执行以查明。

+0

你应该建议在其他领域有同样的问题,你应该解释为什么单引号是必要的 – Jens

+0

是的,谢谢。由于SQL注入,单引号是必要的,并且可以防止上述意外错误。 –

+0

没有单一的qoutes Gas与SQL注入无关。同时添加解释的答案不作为评论 – Jens

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"); 
 
} 
 
}

相关问题