Catchable fatal error: Object of class stdClass

Par bykertix, il y a 10 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.
J'ai cet erreur:

Catchable fatal error: Object of class stdClass could not be converted to string in /home/cristalh/public_html/bykertix/nouveau_topic.php on line 20

et voila mon code:

<?php $Auth->allow('member'); ?> <?php if($Auth->user('id')); ?> <?php $pdo = new PDO('mysql:dbname=c----;host=localhost', 'cr---', 'C---S'); /* Traitement du formulaire de création de Topic */ if(isset($_SESSION['Auth'])) { if(isset($_POST['tsubmit'])) { if(isset($_POST['tsujet'],$_POST['tcontenu'])) { $sujet = htmlspecialchars($_POST['tsujet']); $contenu = htmlspecialchars($_POST['tcontenu']); if(!empty($sujet) AND !empty($contenu)) { if(strlen($sujet) <= 70) { if(isset($_POST['tmail'])) { $notif_mail = 1; } else { $notif_mail = 0; } $ins = $pdo->prepare('INSERT INTO f_topics (id_createur, sujet, contenu, notif_createur, date_heure_creation) VALUES(?,?,?,?,NOW())'); $ins->execute(array($_SESSION['Auth'],$sujet,$contenu,$notif_mail)); // LIGNE 20 --------------------------------------------------------------------------- } else { $terror = "Votre sujet ne peut pas dépasser 70 caractères"; } } else { $terror = "Veuillez compléter tous les champs"; } } } } else { $terror = "Veuillez vous connecter pour poster un nouveau topic"; } require('nouveau_topic.view.php'); /* Appel du fichier "vue" de notre page */ ?>

J'aimerais regler cette erreur

sa fait plusieurs heures que je cherche
merci de votre aide

11 réponses

AlexJM, il y a 10 ans

C'est bien ce que je t'avais dit de faire ^^'

AlexJM, il y a 10 ans

Bonjour,
Peux tu faire :

var_dump(array($_SESSION['Auth'],$sujet,$contenu,$notif_mail));

Juste avant la ligne 20 ?

bykertix, il y a 10 ans

Oui sa me dit sa:

array(4) { [0]=> object(stdClass)#1 (16) { ["id"]=> string(1) "1" ["username"]=> string(8) "ByKeRTiX" ["email"]=> string(23) "gog********" ["password"]=> string(60) "$2y$10$x***********PXhie" ["address"]=> string(9) "Fondateur" ["confirmation_token"]=> NULL ["confirmed_at"]=> string(4) "2015" ["remember_token"]=> NULL ["remember_at"]=> NULL ["reset_token"]=> string(60) "wHDlMrRccBos1UZReGo4SieNpeUnDLeS5ScQQpiv8NGOm90pj4p5BSN3AfxX" ["reset_at"]=> string(19) "2016-03-27 00:50:09" ["role_id"]=> string(1) "1" ["avatar"]=> string(0) "" ["name"]=> string(14) "Administrateur" ["slug"]=> string(5) "admin" ["level"]=> string(1) "2" } [1]=> string(3) "dfd" [2]=> string(4) "dffd" [3]=> int(0) } Catchable fatal error: Object of class stdClass could not be converted to string in /home/cristalh/public_html/bykertix/nouveau_topic.php on line 21
AlexJM, il y a 10 ans

Le problème c'est que $_SESSION['Auth'] est un objet. Remplace le par

$_SESSION['Auth']->id

et je pense que ça ira ;)

bykertix, il y a 10 ans

sa me fait comme si sa actualiser la page
mais sa ne fait rien

AlexJM, il y a 10 ans

C'est à dire ?

bykertix, il y a 10 ans

sa ne poste rien dans la bdd

bykertix, il y a 10 ans

sa marche

$ins->execute(array($_SESSION['Auth']->id,$sujet,$contenu,$notif_mail));
Zicrou, il y a 8 ans

bonjour j'ai cette erreur : Catchable fatal error: Object of class stdClass could not be converted to string in C:\wamp\www\Projet Memoire\Projet_memoire\try.php on line 22
comment faire

Zicrou, il y a 8 ans

voici mon code:
<?php
require_once'include/db.php';
require_once'include/functions.php';
logged_only();
require'include/header.php';

/ REQUETE QUI RECUPERE LES DIFFERRENTES OPTION DANS LA BASE DE DONNEES/
$reqS1=$pdo->query("SELECT DISTINCT metier1 FROM candidats");
$reqS2=$pdo->query("SELECT DISTINCT region FROM candidats");
//$reqS3=$pdo->query("SELECT DISTINCT departement FROM candidats"); //C'est la requete que j'utilise pour lister dans l'autre option du select 2
$afficher="";
$option1="";
$option2="";
$option3="";
if (!empty($_POST)) {
$slct1 = $_POST['slct1'];
$slct2 = $_POST['slct2'];
if ($slct1 !="" AND $slct2 !="") {
$req = "SELECT * FROM candidats WHERE disponibilite='FREE' AND metier1 = ? AND region = ?";
$req3 = $pdo->prepare($req);
$req3->execute(array($slct1, $slct2));
echo $req33=$req3->fetch(); //ligne 20.....
}
}
?>

Zicrou, il y a 8 ans

lorsque je fais un vardump il me retour ca :
array (size=2)
0 => string 'macon' (length=5)
1 => string 'dakar' (length=5)