Probleme : Notice: Undefined index

Fermé
jrmieo123 Messages postés 1 Date d'inscription mercredi 19 janvier 2011 Statut Membre Dernière intervention 19 janvier 2011 - 19 janv. 2011 à 07:09
Akronos Messages postés 140 Date d'inscription jeudi 6 janvier 2011 Statut Membre Dernière intervention 31 janvier 2011 - 19 janv. 2011 à 13:16
Bonjour,

Je commence l'HTML et le PHP depuis quelques jours, j'ai un souci d'index dans un code. J'ai cru comprendre que je n'avais pas initialisé ma variables au préalable ! J'ai regardé pas mal de choses sur le net mais je n'arrive pas à corriger ! est ce que quelqu'un sit comment corriger les deux erreurs suivantes :

Notice: Undefined index: tout in C:\wamp\www\Webory\Association.php on line 87

Notice: Undefined index: select_association in C:\wamp\www\Webory\Association.php on line 122






<div id="Les Associations">

<form action="association.php" method="POST" name="form1" id="form1">
<select name="select_association" id="association" type="text">
<?php require("connecter.php");

$query = "SELECT * FROM association ORDER BY Nom_Asso";
$result = mysql_query($query) or die ("erreur requete");
$val = mysql_fetch_array($result);
?>
<?php do { ?>
<option>
<?php
echo $val['Nom_Asso']; ?>
</option>
<?php } while ($val = mysql_fetch_assoc($result)); ?>
</select>
<h4> <input type="checkbox" name="tout"/>Afficher toutes les associations</h4>
<input name="Executer" type="submit" id="button" value="Afficher association(s)" />
</form>
</div>

<div class="Article" >
<h3 class="nom">Le(s) Association(s) recherchée(s)<br /></h3>


<?php

if ($_POST["tout"]=="on"){?>
<table border="1px" width="792px">
<tr>
<td width="150px"></td>
<td width="150px"><h3 class="nom">Nom Association</h3></td >
<td width="150px"><h3 class="nom">Type Association</h3></td >
<td width="150px"><h3 class="nom">Prix Association</h3></td >
<td width="150px"><h3 class="nom">Cotisation Annuel</h3></td >
<?php
$query = "SELECT * FROM association ORDER BY Nom_Asso";
$result = mysql_query($query) or die ("erreur requete");
while ($val = mysql_fetch_array($result)){
$image = $val['Logo_Asso'];
$nom = $val['Nom_Asso'];
$type =('Type_Asso');
$prix = $val['Prix_Adhesion_Asso'];
$cotisation = "A calculer";
print "<tr><td>"; ?>

<img src="images/<?php print "$image"; ?>" width="150px" /> <?php print"</td>";
print "<td>$nom</td><td>$val[Type_Asso]</td><td>$val[Prix_Adhesion_Asso] Euros</td><td>$cotisation</td>
</tr>";
}
?>
</table>
<?php }
else {?>
<table border="1px" width="792px">
<tr>
<td width="150px"></td>
<td width="150px"><h3 class="nom">Nom Association</h3></td >
<td width="150px"><h3 class="nom">Type Association</h3></td >
<td width="150px"><h3 class="nom">Prix Association</h3></td >
<td width="150px"><h3 class="nom">Cotisation Annuel</h3></td >
<?php
$dcherche = $_POST["select_association"];
$query = "SELECT * FROM association WHERE Nom_Asso = \"$dcherche\"" ;
$result = mysql_query($query) or die ("erreur requete");
while ($val = mysql_fetch_array($result)){
$image = $val['Logo_Asso'];
$nom = $val['Nom_Asso'];
$type = Type_Asso;
$prix = $val['Prix_Adhesion_Asso'];
$cotisation = "A calculer";
print "<tr><td>" ; ?>
<img src="images/<?php print "$image"; ?>" width="150px" /> <?php print"</td>";
print "<td>$val[Nom_Asso]</td> <td>$val[Type_Asso]</td> <td>$val[Prix_Adhesion_Asso] Euros</td><td>$cotisation</td></tr>";
}
?>
</table>




2 réponses

Zep3k!GnO Messages postés 2025 Date d'inscription jeudi 22 septembre 2005 Statut Membre Dernière intervention 18 novembre 2015 200
19 janv. 2011 à 12:43
"Undefined index" : Signifie que tu veux accéder à un index qui n'existe pas d'un tableau.
Pour débugger ça, facile, il suffit d'afficher le contenu de ton tableau avec la fonction print_r() : https://www.php.net/manual/fr/function.print-r.php , tu vas alors t'apercevoir de ton erreur.
Rapidement, si je reprend ton script :
//On affiche le contenu de post pour que tu puisses voir ce qu'il y a dedans.
echo "<pre>".print_r($_POST, true)."</pre>";

$dcherche = $_POST["select_association"];  //l'erreur est ici
0
Akronos Messages postés 140 Date d'inscription jeudi 6 janvier 2011 Statut Membre Dernière intervention 31 janvier 2011 32
19 janv. 2011 à 13:16
T'as lein de truc du genre:
print"<td>$val[Nom_Asso]</td> <td>$val[Type_Asso]</td>"
Au lieu de:
print"<td>" . $val['Nom_Asso'] . "</td> <td>" . $val['Type_Asso'] . "</td>"
0