par
rimie » 18 juil. 2011, 05:03
Bonjour,
Je fais un code de test afin de recuperer les donnees d'une table, et affiche lerreur suivante:
Notice: Undefined index: id on line 30
sachant que ce champs existe dans la table
voici le code:
<?php
$PARAM_nom_bd = 'tests';
try
{
$connexion = new PDO('mysql:host='.$PARAM_hote.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe
, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
catch(Exception $e)
{
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
}
$queryT = 'SELECT * FROM admin WHERE id = ? ;';
$prepT = $connexion->prepare($queryT);
$prepT->bindValue(1, $id, PDO::PARAM_INT);
$prepT->execute();
$arrAllT = $prepT->fetchAll();
if(!empty($arrAllT))
{
foreach($arrAllT as $arrT)
{
$id = $arrAllT['id']; // ligne 30
echo $id;
}
}
else
{
echo 'aucun resultat';
}
?>
Bonjour,
Je fais un code de test afin de recuperer les donnees d'une table, et affiche lerreur suivante:
[quote]
Notice: Undefined index: id on line 30
[/quote]
sachant que ce champs existe dans la table
voici le code:
[php]
<?php
$PARAM_nom_bd = 'tests';
try
{
$connexion = new PDO('mysql:host='.$PARAM_hote.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe
, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
catch(Exception $e)
{
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
}
$queryT = 'SELECT * FROM admin WHERE id = ? ;';
$prepT = $connexion->prepare($queryT);
$prepT->bindValue(1, $id, PDO::PARAM_INT);
$prepT->execute();
$arrAllT = $prepT->fetchAll();
if(!empty($arrAllT))
{
foreach($arrAllT as $arrT)
{
$id = $arrAllT['id']; // ligne 30
echo $id;
}
}
else
{
echo 'aucun resultat';
}
?>
[/php]