Erreur can not use stdclass object as array on line 49
Résolu
LearnDeep
Messages postés
67
Date d'inscription
Statut
Membre
Dernière intervention
-
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour , j'ai une erreur et je ne sais pas quoi faire pour résoudre ce problème.
<?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Credentials: true "); header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); header("Access-Control-Allow-Headers: X-Custom-Header, Origin, Content-Type , Authorisation , X-Requested-With"); header("Content-Type: application/json; charset=UTF-8 "); header("Referrer-Policy: origin-when-cross-origin"); header("Expect-CT: max-age=7776000, enforce"); header('Strict-Transport-Security: max-age=16070400; includeSubDomains'); header('X-XSS-Protection: 1; mode=block'); header('X-Content-Type-Options: nosniff'); header('X-Frame-Options: SAMEORIGIN'); $json = file_get_contents('php://input'); $decoded = json_decode($json); $id = htmlspecialchars($decoded->id, ENT_QUOTES); $total = htmlspecialchars($decoded->prix, ENT_QUOTES); function conn() { try{ $bdd =new PDO('mysql:host=*****.mysql.db; dbname=*****; charset=utf8', '*****', '*****'); $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $bdd->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); } catch(PDOException $e) { die('Erreur : ' . $e->getMessage()); } return $bdd; } if(empty($id) || empty($total) || !is_numeric($total)){ json_encode(false); die; }else{ $db = conn(); $r = $db->prepare("SELECT id,adresse,tel FROM user WHERE email = ? "); $r->execute([$id]); $v = $r->fetchAll(); $i = $v[0][0]; $d = $v[0][1]; $t = $v[0][2]; $prepred = $db->prepare("INSERT INTO commandes (etat, adresse, tel, prix, idUser) VALUES('En Cours',?,?,?,?)"); $prepred->execute([$d, $t, $total, $i]); $x = $db->prepare("SELECT numCmd FROM commandes WHERE idUser = ? and etat = 'En Cours' "); $x->execute([$i]); $y = $x->fetchAll(); $r = $y[sizeof($y)-1][0]; echo json_encode($r); } ?>
A voir également:
- Erreur can not use stdclass object as array on line 49
- We are working on it and we'll get it fixed as soon as we can. ✓ - Forum Facebook
- Sorry, something went wrong. we're working on getting this fixed as soon as we can. ✓ - Forum Facebook
- We're working on getting this fixed as soon as we can. ✓ - Forum Facebook
- Use iphone as webcam - Guide
- Erreur 3000 france tv - Forum Lecteurs et supports vidéo
et donc.. il parait normal que tu aies un message indiquant que tu ne peux pas utiliser un objet en tant qu'array... vu que ta variable $y provient de ta requête....
et que le mode de fetch que tu as choisi est le mode objet
Fais donc un var_dump de ta variable pour voir de quel type elle est et ce qu'elle contient...