[RESOLU] Erreur Trying to access array offset on value of type bool

Avatar du membre
Eléphant du PHP | 70 Messages

02 juin 2021, 14:18

Essaye ceci à la place de ta connexion :
try {
			$dbh = new PDO("mysql:host=localhost;dbname=chrstock", "root", "");
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		} catch(PDOException $e) {
			die('Connexion failed : '.$e->getMessage());
		}
Pour l'affichage des erreurs

EDIT : Si juste apres ton query tu met ceci :
$donnees=$reponse->fetchAll(PDO::FETCH_ASSOC);
var_dump($donnees);
Que t'affiche t'il ?
" La révolution informatique fait gagner un temps fou aux Hommes, mais ils le passent avec leur ordinateur ! " by Khalil Assala

iso
Eléphanteau du PHP | 11 Messages

03 juin 2021, 09:01

Désolé je n'avais pas vu t'as réponse et rien ne semble fonctionner le var_dump n'affiche rien

EDIT: j'ai pas assez dormi j'ai modifié le mauvais fichier ...
le var_dump m'affiche:

array(37) { [0]=> array(2) { ["ref"]=> string(8) "JZH-TC-2" ["stock"]=> string(3) "oui" } [1]=> array(2) { ["ref"]=> string(8) "JUS-RQ-4" ["stock"]=> string(3) "oui" } [2]=> array(2) { ["ref"]=> string(5) "AAF6P" ["stock"]=> string(3) "non" } [3]=> array(2) { ["ref"]=> string(5) "AAF6N" ["stock"]=> string(3) "non" } [4]=> array(2) { ["ref"]=> string(6) "AAF12P" ["stock"]=> string(3) "non" } [5]=> array(2) { ["ref"]=> string(6) "AAF12N" ["stock"]=> string(3) "non" } [6]=> array(2) { ["ref"]=> string(5) "AAF7P" ["stock"]=> string(3) "non" } [7]=> array(2) { ["ref"]=> string(5) "AAF7N" ["stock"]=> string(3) "non" } [8]=> array(2) { ["ref"]=> string(6) "AAF14P" ["stock"]=> string(3) "non" } [9]=> array(2) { ["ref"]=> string(6) "AAF14N" ["stock"]=> string(3) "non" } [10]=> array(2) { ["ref"]=> string(5) "AA7PP" ["stock"]=> string(3) "oui" } [11]=> array(2) { ["ref"]=> string(6) "AAS901" ["stock"]=> string(3) "oui" } [12]=> array(2) { ["ref"]=> string(7) "AAS903T" ["stock"]=> string(3) "non" } [13]=> array(2) { ["ref"]=> string(5) "AA7PN" ["stock"]=> string(3) "oui" } [14]=> array(2) { ["ref"]=> string(7) "AAS900V" ["stock"]=> string(3) "oui" } [15]=> array(2) { ["ref"]=> string(7) "AAS903V" ["stock"]=> string(3) "non" } [16]=> array(2) { ["ref"]=> string(7) "AAPS900" ["stock"]=> string(3) "non" } [17]=> array(2) { ["ref"]=> string(7) "AAPS903" ["stock"]=> string(3) "non" } [18]=> array(2) { ["ref"]=> string(6) "AAS2PP" ["stock"]=> string(3) "oui" } [19]=> array(2) { ["ref"]=> string(6) "AAS3PP" ["stock"]=> string(3) "non" } [20]=> array(2) { ["ref"]=> string(6) "AAS2PD" ["stock"]=> string(3) "non" } [21]=> array(2) { ["ref"]=> string(6) "AAS3PD" ["stock"]=> string(3) "non" } [22]=> array(2) { ["ref"]=> string(5) "AA2PP" ["stock"]=> string(3) "non" } [23]=> array(2) { ["ref"]=> string(5) "AA3PP" ["stock"]=> string(3) "non" } [24]=> array(2) { ["ref"]=> string(5) "AA4PP" ["stock"]=> string(3) "non" } [25]=> array(2) { ["ref"]=> string(5) "AA2PD" ["stock"]=> string(3) "non" } [26]=> array(2) { ["ref"]=> string(5) "AA3PD" ["stock"]=> string(3) "non" } [27]=> array(2) { ["ref"]=> string(5) "AA4PD" ["stock"]=> string(3) "non" } [28]=> array(2) { ["ref"]=> string(5) "AA2PZ" ["stock"]=> string(3) "non" } [29]=> array(2) { ["ref"]=> string(5) "AA3PZ" ["stock"]=> string(3) "non" } [30]=> array(2) { ["ref"]=> string(6) "AA28PP" ["stock"]=> string(3) "oui" } [31]=> array(2) { ["ref"]=> string(6) "AA38PP" ["stock"]=> string(3) "non" } [32]=> array(2) { ["ref"]=> string(9) "AA28PPDM2" ["stock"]=> string(3) "oui" } [33]=> array(2) { ["ref"]=> string(9) "AA38PPDM3" ["stock"]=> string(3) "non" } [34]=> array(2) { ["ref"]=> NULL ["stock"]=> NULL } [35]=> array(2) { ["ref"]=> NULL ["stock"]=> NULL } [36]=> array(2) { ["ref"]=> NULL ["stock"]=> NULL } }

Avatar du membre
Eléphant du PHP | 70 Messages

03 juin 2021, 10:53

Donc ta connexion à ta BDD est bonne ...

Pourquoi mettre un ";" après ton while ?

Tu as d'ailleurs récupéré toutes les infos, donc le while n'est pas utile dans ce cas : Essaye de passer par un foreach
foreach($donnees as $value) : ?>
	<tr>
		<td><?= $value['ref'] ?></td>
		<td><?= $value['stock'] ?></td>
		<td></td>
		<td></td>
	</tr>
<?php
endforeach;
echo '</table>';
EDIT : Pense bien à remettre $donnees = $reponse->fetch(); après ta query
" La révolution informatique fait gagner un temps fou aux Hommes, mais ils le passent avec leur ordinateur ! " by Khalil Assala

iso
Eléphanteau du PHP | 11 Messages

03 juin 2021, 11:25

c'était ce ';' qui me causais tant de soucis ! merci beaucoup pour ton aide