jeudi 16 juin 2016

Fatal error: Object of class mysqli_stmt could not be converted to string

I'm new to PHP so this question must be quite dumb. I've read the code many times but I'm unable to find any discrepancy about those errors:

PHP Catchable fatal error: Object of class mysqli_stmt could not be converted to string in mkt_salva_prodotti.php on line 80

PHP Catchable fatal error: Object of class mysqli_stmt could not be converted to string in mkt_salva_prodotti.php on line 89

Following is the code:

<?php

require "common/header.php" ;

$token=getPar_empty("token",$_GET);
if ($token=="")$token=getPar_empty("token",getallheaders());
auth($token);

$nome_it=getPar_empty("nome_it",$_POST,null);
$nome_en=getPar_empty("nome_en",$_POST,null);

$descrizione_it=getPar_empty("descrizione_it",$_POST,null);
$descrizione_en=getPar_empty("descrizione_en",$_POST,null);
$imm_url=getPar_empty("imm_url",$_POST,null);
$lat=getPar_empty("lat",$_POST,null);
$lng=getPar_empty("lng",$_POST,null);
$posto=getPar_empty("posto",$_POST,null);
$id=getPar_empty("id",$_POST,null);
$lingua=getPar_empty("lingua",$_POST,null);
$id_produttore=getPar_empty("id_produttore",$_POST,null);
$quantita_min=(integer)getPar_empty("quantita_min",$_POST,0);
$quantita_max=(integer)getPar_empty("quantita_max",$_POST,0);
$quantita_disp=(integer)getPar_empty("quantita_disp",$_POST,0);
$costo=(float)getPar_empty("costo",$_POST,0);
$tasse=(float)getPar_empty("tasse",$_POST,0);
$completo_it=(integer)getPar_empty("completo_it",$_POST,1);
$completo_en=(integer)getPar_empty("completo_en",$_POST,1);

$lat2=getPar_empty("lat2",$_POST,null);
$lng2=getPar_empty("lng2",$_POST,null);
$posto2=getPar_empty("posto2",$_POST,null);

$lat3=getPar_empty("lat3",$_POST,null);
$lng3=getPar_empty("lng3",$_POST,null);
$posto3=getPar_empty("posto3",$_POST,null);


$user=getPar_empty("user",$_POST);
$system=getPar_empty("system",$_POST);

$out=array("res"=>"0");
$db->autocommit(FALSE);


if (isset($_POST['del_ingr']) && $_POST['del_ingr']==1){
    $stmt=$db->prepare("UPDATE prodotti set online=0,data_update=now(),sistema=?, utente=? where id=?");
    if (!$stmt) {
        log_msg($db->error);
        $db->rollback ();
        die();
    }

    $stmt->bind_param("sss",$system,$user,$id);
    $stmt->execute();
    $db->commit();
    $db->close();

    $out["res"]="1";
    echo json_encode($out);
    die();
}

if (!$id) $id=get_a_slug($nome_it.'-'.$nome_en."_".bin2hex(openssl_random_pseudo_bytes(3)));
if (!$id) die();


$stmt=$db->prepare("UPDATE prodotti set nome=?,descrizione=?,completo=? where id=? and lingua='it'");
if (!$stmt) {
    log_msg($db->error);
    $db->rollback ();
    die();
}

$stmt->bind_param("ssis",
$nome_it,$descrizione_it,$completo_it,$id);
if (test_execute($stmt->execute()) ) $out['it']=1;

if ($db->affected_rows==0){
    $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo) VALUES (?,?,?,'it',?)");

    if (!$stmt) {
        log_msg($db->error);
        $db->rollback ();
        die();
    }

    $stmt->bind_param("ssis",
    $nome_it,$descrizione_it,$completo_it,$id);
    if (test_execute($stmt->execute())) $out['it']=1;
}

$stmt=$db->prepare("UPDATE prodotti set nome=? ,descrizione=?,completo=? where id=? and lingua='en'");
if (!$stmt) {
    log_msg($db->error);
    die();
}

$stmt->bind_param("ssis",
$nome_en,$descrizione_en,$completo_en,$id);
if (test_execute($stmt->execute()) ) $out['en']=1;

if ($db->affected_rows==0){
    $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo) VALUES (?,?,?,'en',?)");
    if (!$stmt) {

        log_msg($db->error);
        $db->rollback ();
        die();
    }

    $stmt->bind_param("ssis",
    $nome_en,$descrizione_en,$completo_en,$id);
    if ($stmt->execute()) $out['en']=1;
}


if ($imm_url && $imm_url!=IMAGE_PLACEHOLDER && file_exists(ROOT_DIR.$imm_url)){
    $stmt=$db->prepare("select imm_url from prodotti where id=?  LIMIT 0,1");
    if (!$stmt) {

        log_msg($db->error);
        $db->rollback ();
        die();
    }
    $stmt->bind_param("s", $id);
    $stmt->execute();
    $row=fetchArray($stmt);
    $stmt->close();

    if (count($row)==1){
        offline_s3_archivio($row[0]["imm_url"],$system,$user);
    }



    $array=null;
    $id_s3=crea_s3_archivio_immagini(ROOT_DIR.$imm_url,$system,$user,$array,false);
    if ($id_s3==0) {


        $db->rollback ();
        die();
    }

    $stmt=$db->prepare("UPDATE prodotti set imm_url=?  where id=?");
    if (!$stmt) {
        log_msg($db->error);
        $db->rollback ();
        die();
    }

    $stmt->bind_param("ss", $id_s3,$id);
    if ($stmt->execute()) {
        $out['file']=$array["big"];
        $out['archive']=$id_s3;
    }

}


$posti=array();
if ($lat && $lng && $posto){
    array_push($posti,array("lat"=>$lat,"lng"=>$lng,"posto"=>$posto));
}
if ($lat2 && $lng2 && $posto2){
    array_push($posti,array("lat"=>$lat2,"lng"=>$lng2,"posto"=>$posto2));
}
if ($lat3 && $lng3 && $posto3){
    array_push($posti,array("lat"=>$lat3,"lng"=>$lng3,"posto"=>$posto3));
}

if ($posti && count($posti)>0){
    $to=json_encode($posti);
    $stmt=$db->prepare("UPDATE prodotti set mappa=?  where id=?");
    if (!$stmt) {
        log_msg($db->error);
        $db->rollback ();
        die();
    }

    $stmt->bind_param("ss", $to,$id);
    if ($stmt->execute()) $out['mappa']=$to;

}


$stmt=$db->prepare("UPDATE prodotti set quantita_min=?,quantita_max=?,quantita_disp=?,costo=?,tasse=?  where id=?");
if (!$stmt) {
    log_msg($db->error);
    $db->rollback ();
    die();
}

$stmt->bind_param("iiidds", $quantita_min,$quantita_max,$quantita_disp,$costo,$tasse,$id);
if ($stmt->execute()) $out['dati']=1;


if (isset($out['en']) && isset($out['it']) && $out['en']==1 && $out['it']==1) {
    $out["res"]="1";
    $out["id"]=$id;
}


$stmt=$db->prepare("UPDATE prodotti set data_update=now(),sistema=?, utente=? where id=?");
    if (!$stmt) {
        log_msg($db->error);
        $db->rollback ();
        die();
    }

$stmt->bind_param("sss", $system,$user,$id);
$stmt->execute();
$stmt->close();



$db->commit();
$db->close();


echo json_encode($out);

?>

Kindly help me on this. Thank you!

Aucun commentaire:

Enregistrer un commentaire