I am trying to insert data into a table but getting this error- Catchable fatal error: Object of class mysqli_result could not be converted to string on line 44 the error is showing for the following line.捕获的致命错误:类mysqli_result的对象不能被转换成字符串上线44
$query= "insert into product(proname,prodesc,proprice,proimg,catid) values('$proname','$prodesc','$proprice','$file_path','$catid')";
if(mysqli_query($conn,$query)){
header('location:product.php');
}
else{
echo 'cant insert data'.mysqli_error($conn);
}
}
}
?>
following is the entire program
$errors=array();
if(!(empty($_POST))){
$proname=$_POST['proname'];
$proprice=$_POST['proprice'];
$prodesc=$_POST['prodesc'];
$catname=$_POST['cat'];
$catid=mysqli_query($conn,"select catid from category where catname='$catname'") or die('cant get category id'.mysqli_error($conn));
if(empty($proname) or empty($proprice)){
$errors[]='Please enter product name and price.';
}
if(isset($_FILES['proimg'])){
$file_name = $_FILES['proimg']['name'];
$file_size =$_FILES['proimg']['size'];
$file_tmp =$_FILES['proimg']['tmp_name'];
$file_type=$_FILES['proimg']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['proimg']['name'])));
$expensions= array("jpeg","jpg","png");
$file_path='imgproduct/'.$file_name;
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
}
else{
$errors[]='Please upload an image of product';
}
if(!(empty($errors))){
print_r($errors);
}
else{
if(!(move_uploaded_file($file_tmp,$file_path))) {
echo '1.file not uploaded';
exit;
}
$query= "insert into product(proname,prodesc,proprice,proimg,catid) values('$proname','$prodesc','$proprice','$file_path','$catid')";
if(mysqli_query($conn,$query)){
header('location:product.php');
}
else{
echo 'cant insert data'.mysqli_error($conn);
}
}
}
?>
当你表达你希望成为一个优秀的程序员,让我给你一个提醒:一个优秀的程序员总是读错误消息。 –
@你的常识,是的先生,你的绝对正确。我应该首先关注错误消息。感谢您的建议。我非常感谢有人建议像你这样的人。 –
@你的常识,不仅给出这个问题的答案时间,而且我应该总是遵循错误信息,来自系统的错误。谢谢你,先生。我很高兴我会遇见像你这样的人,尽管这是一个虚拟的世界。 –