Probleme : Notice: Undefined index
jrmieo123
Messages postés
1
Statut
Membre
-
Akronos Messages postés 163 Statut Membre -
Akronos Messages postés 163 Statut Membre -
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>
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
"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 :
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