ERREUR PHP HELPP
Lusitano25
Messages postés
5
Statut
Membre
-
hack_net Messages postés 814 Statut Membre -
hack_net Messages postés 814 Statut Membre -
Bonjour,
Voici mon code :
----------------------------------------------------------------------------------------------------------------------------------------------
<!-- CREATION DES ARTICLES -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/style.css">
<img src="../images/header.jpg">
<script language="javascript" src="script/script.js"></script>
<script language="javascript" src="script/mootools-1.2.4-core-jm.js"></script>
</head>
<?php
include("login.php");
$connexion=mysql_connect("$db_host","$db_log","$db_pwd");
mysql_select_db($db_name) or die ("problème de connexion");
$code = $_POST['code'];
$designation = $_POST['designation'];
$type = $_POST['type'];
$couleur = $_POST['couleur'];
$taille = $_POST['taille'];
$prix = $_POST['prix'];
$qte = $_POST['qte'];
if(isset($_POST['valider']))
{
$sql= "INSERT INTO ansf_articles(art_code,art_designation,art_type,art_couleur,art_taille,art_prix,art_qte) VALUES ('$code','$designation','$type','$couleur','$taille','$prix','$qte')";
$req= "UPDATE ansf_articles SET art_valeur = art_prix * art_qte WHERE art_code=".$code."";
mysql_query($sql);
mysql_query($req);
mysql_close($connexion);
echo '<img src="../images/validation.jpg">Article créé';
}
if(isset($_POST['new']))
{
echo '<img src="../images/new.jpg"> Nouvel Ajout';
}
?>
<body>
<div id="corp">
<div id="haut">
<table width="100%" height="100%"><tr><td id="image" height="100%" width="100%"></td></tr></table>
</div>
<div id="menu_gauche"><br/>
<span id="accueil" onMouseOver="affichage('accueil');" onMouseOut="affichage2('accueil');"><a href="../accueil.php">Accueil</a></span><br/><br/>
<span id="creer" onMouseOver="affichage('creer');" onMouseOut="affichage2('creer');"><a href="php/creation_art.php">Créer un article</a></span><br/><br/>
<span id="vente" onMouseOver="affichage('vente');" onMouseOut="affichage2('vente');"><a href="php/vente_art.php">Ventes d'aricle</a></span><br/><br/>
<span id="achat" onMouseOver="affichage('achat');" onMouseOut="affichage2('achat');"><a href="php/achat_art.php">achats fournisseurs</a></span><br/><br/>
<span id="stock" onMouseOver="affichage('stock');" onMouseOut="affichage2('stock');"><a href="php/stockmanif.php">Stock Manifestation</a></span><br/><br/>
<span id="fiche" onMouseOver="affichage('fiche');" onMouseOut="affichage2('fiche');"><a href="php/stock.php">Fiche de stock</a></span><br/><br/>
<span id="client" onMouseOver="affichage('client');" onMouseOut="affichage2('client');"><a href="php/clients.php">Liste des clients</a></span><br/><br/>
<span id="fourn" onMouseOver="affichage('fourn');" onMouseOut="affichage2('fourn');"><a href="">Liste des fournisseurs</a></span>
</div>
<div id="centre">
<FORM method="post" action="' .$_SERVER['PHP_SELF']. '">
<FIELDSET>
<LEGEND align=top> <b>Créer un article</b> </LEGEND><br>
<u>Code</u> : <INPUT name="code" type="text" size="40">
<u>Designation</u> : <INPUT name="designation" type="text" size="40"><br><br>
<u>Type</u> : <SELECT name="type">
<OPTION VALUE="manches courtes">Manches courtes </OPTION>
<OPTION VALUE="manches longues">Manches longues</OPTION>
</SELECT>
<u>Couleur</u> : <SELECT name="couleur">
<OPTION VALUE="bleu marine">Bleu marine</OPTION>
<OPTION VALUE="blanc">Blanc</OPTION>
</SELECT><br><br>
<u>Taille</u> : <SELECT name="taille">
<OPTION VALUE="S">S</OPTION>
<OPTION VALUE="M">M</OPTION>
<OPTION VALUE="L">L</OPTION>
<OPTION VALUE="XL">XL</OPTION>
<OPTION VALUE="XXL">XXL</OPTION>
<OPTION VALUE="XXXL">XXXL</OPTION>
</SELECT>
<u>Prix</u> : <INPUT name="prix" type="text" size="40">
<u>Quantité</u> : <INPUT name="qte" type="text" size="40"><br><br>
<input type="submit" name="valider" value="Ajouter" />
<input type="submit" name="new" value="Nouveau" /><br/><br/>
</FIELDSET>
</FORM>
</div>
</div>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------------------
Voici mes erreurs :
--------------------------------------------------------------------------------------------------------------------------------------------
Notice: Undefined index: code in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 16
Notice: Undefined index: designation in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 17
Notice: Undefined index: type in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 18
Notice: Undefined index: couleur in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 19
Notice: Undefined index: taille in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 20
Notice: Undefined index: prix in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 21
Notice: Undefined index: qte in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 22
--------------------------------------------------------------------------------------------------------------------------------------------
Pourtant je ne comprend pas, car ce sont bien les noms des inputs, donc je ne vois pas pourquoi j'ai une erreur.
Quant aux requetes, lorsque je les test, elles fonctionnent ( cet erreur ne vient pas que sur cet page );
Je précis que dans les inputs en readonly, je veux faire apparaitre le resultat d'une requete par rapport au code saisie.
Cela fait maitenant depuis hier matin que je cherche mon erreur, et je ne comprend toujours pas...
Si quelqu'un peut m'aider, ça serait assez sympas :)
Voici mon code :
----------------------------------------------------------------------------------------------------------------------------------------------
<!-- CREATION DES ARTICLES -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/style.css">
<img src="../images/header.jpg">
<script language="javascript" src="script/script.js"></script>
<script language="javascript" src="script/mootools-1.2.4-core-jm.js"></script>
</head>
<?php
include("login.php");
$connexion=mysql_connect("$db_host","$db_log","$db_pwd");
mysql_select_db($db_name) or die ("problème de connexion");
$code = $_POST['code'];
$designation = $_POST['designation'];
$type = $_POST['type'];
$couleur = $_POST['couleur'];
$taille = $_POST['taille'];
$prix = $_POST['prix'];
$qte = $_POST['qte'];
if(isset($_POST['valider']))
{
$sql= "INSERT INTO ansf_articles(art_code,art_designation,art_type,art_couleur,art_taille,art_prix,art_qte) VALUES ('$code','$designation','$type','$couleur','$taille','$prix','$qte')";
$req= "UPDATE ansf_articles SET art_valeur = art_prix * art_qte WHERE art_code=".$code."";
mysql_query($sql);
mysql_query($req);
mysql_close($connexion);
echo '<img src="../images/validation.jpg">Article créé';
}
if(isset($_POST['new']))
{
echo '<img src="../images/new.jpg"> Nouvel Ajout';
}
?>
<body>
<div id="corp">
<div id="haut">
<table width="100%" height="100%"><tr><td id="image" height="100%" width="100%"></td></tr></table>
</div>
<div id="menu_gauche"><br/>
<span id="accueil" onMouseOver="affichage('accueil');" onMouseOut="affichage2('accueil');"><a href="../accueil.php">Accueil</a></span><br/><br/>
<span id="creer" onMouseOver="affichage('creer');" onMouseOut="affichage2('creer');"><a href="php/creation_art.php">Créer un article</a></span><br/><br/>
<span id="vente" onMouseOver="affichage('vente');" onMouseOut="affichage2('vente');"><a href="php/vente_art.php">Ventes d'aricle</a></span><br/><br/>
<span id="achat" onMouseOver="affichage('achat');" onMouseOut="affichage2('achat');"><a href="php/achat_art.php">achats fournisseurs</a></span><br/><br/>
<span id="stock" onMouseOver="affichage('stock');" onMouseOut="affichage2('stock');"><a href="php/stockmanif.php">Stock Manifestation</a></span><br/><br/>
<span id="fiche" onMouseOver="affichage('fiche');" onMouseOut="affichage2('fiche');"><a href="php/stock.php">Fiche de stock</a></span><br/><br/>
<span id="client" onMouseOver="affichage('client');" onMouseOut="affichage2('client');"><a href="php/clients.php">Liste des clients</a></span><br/><br/>
<span id="fourn" onMouseOver="affichage('fourn');" onMouseOut="affichage2('fourn');"><a href="">Liste des fournisseurs</a></span>
</div>
<div id="centre">
<FORM method="post" action="' .$_SERVER['PHP_SELF']. '">
<FIELDSET>
<LEGEND align=top> <b>Créer un article</b> </LEGEND><br>
<u>Code</u> : <INPUT name="code" type="text" size="40">
<u>Designation</u> : <INPUT name="designation" type="text" size="40"><br><br>
<u>Type</u> : <SELECT name="type">
<OPTION VALUE="manches courtes">Manches courtes </OPTION>
<OPTION VALUE="manches longues">Manches longues</OPTION>
</SELECT>
<u>Couleur</u> : <SELECT name="couleur">
<OPTION VALUE="bleu marine">Bleu marine</OPTION>
<OPTION VALUE="blanc">Blanc</OPTION>
</SELECT><br><br>
<u>Taille</u> : <SELECT name="taille">
<OPTION VALUE="S">S</OPTION>
<OPTION VALUE="M">M</OPTION>
<OPTION VALUE="L">L</OPTION>
<OPTION VALUE="XL">XL</OPTION>
<OPTION VALUE="XXL">XXL</OPTION>
<OPTION VALUE="XXXL">XXXL</OPTION>
</SELECT>
<u>Prix</u> : <INPUT name="prix" type="text" size="40">
<u>Quantité</u> : <INPUT name="qte" type="text" size="40"><br><br>
<input type="submit" name="valider" value="Ajouter" />
<input type="submit" name="new" value="Nouveau" /><br/><br/>
</FIELDSET>
</FORM>
</div>
</div>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------------------
Voici mes erreurs :
--------------------------------------------------------------------------------------------------------------------------------------------
Notice: Undefined index: code in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 16
Notice: Undefined index: designation in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 17
Notice: Undefined index: type in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 18
Notice: Undefined index: couleur in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 19
Notice: Undefined index: taille in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 20
Notice: Undefined index: prix in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 21
Notice: Undefined index: qte in C:\Program Files\EasyPHP5.3.0\www\ANSF\php\creation_art.php on line 22
--------------------------------------------------------------------------------------------------------------------------------------------
Pourtant je ne comprend pas, car ce sont bien les noms des inputs, donc je ne vois pas pourquoi j'ai une erreur.
Quant aux requetes, lorsque je les test, elles fonctionnent ( cet erreur ne vient pas que sur cet page );
Je précis que dans les inputs en readonly, je veux faire apparaitre le resultat d'une requete par rapport au code saisie.
Cela fait maitenant depuis hier matin que je cherche mon erreur, et je ne comprend toujours pas...
Si quelqu'un peut m'aider, ça serait assez sympas :)
A voir également:
- ERREUR PHP HELPP
- Expert php pinterest - Télécharger - Langages
- Erreur 0x80070643 - Accueil - Windows
- Erreur 4201 france tv ✓ - Forum Réseaux sociaux
- Erreur 4101 france tv - Forum Lecteurs et supports vidéo
- Code erreur f3500-31 ✓ - Forum Bbox Bouygues
3 réponses
Dans ton form, tu met ton " .$_SERVER['PHP_SELF']." en html et non en php ! il faudrait l'écrire "<?php echo $_SERVER['PHP_SELF']; ?>", mais bref, tu n'en a pas besoin puisque c'est sur la même page, laisse vide ;)
Prends ce code et dis moi s'il marche :
A+
Prends ce code et dis moi s'il marche :
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/style.css">
<img src="../images/header.jpg">
<script language="javascript" src="script/script.js"></script>
<script language="javascript" src="script/mootools-1.2.4-core-jm.js"></script>
</head>
<?php
include("login.php");
$connexion=mysql_connect("$db_host","$db_log","$db_pwd");
mysql_select_db($db_name) or die ("problème de connexion");
extract($_POST); // cela converti les $_POST['var'] en $var ;) plus simple que ta liste de ouf XD et ça évite les erreurs ;)
if(isset($valider)){
$reql= mysql_query"INSERT INTO ansf_articles VALUES ('$code','$designation','$type','$couleur','$taille','$prix','$qte')");
$req2= mysql_query"UPDATE ansf_articles SET art_valeur = art_prix * art_qte WHERE art_code=".$code."");
if($req1 && $req2){ // si pas d'erreur dans les exécutions de requette
mysql_close($connexion);
echo '<img src="../images/validation.jpg">Article créé';
}
else{
echo "Erreur lors de l'exécution des requettes";
}
}
elseif(isset($_POST['new'])){
echo '<img src="../images/new.jpg"> Nouvel Ajout';
}
?>
<body>
<div id="corp">
<div id="haut">
<table width="100%" height="100%"><tr><td id="image" height="100%" width="100%"></td></tr></table>
</div>
<div id="menu_gauche"><br/>
<span id="accueil" onMouseOver="affichage('accueil');" onMouseOut="affichage2('accueil');"><a href="../accueil.php">Accueil</a></span><br/><br/>
<span id="creer" onMouseOver="affichage('creer');" onMouseOut="affichage2('creer');"><a href="php/creation_art.php">Créer un article</a></span><br/><br/>
<span id="vente" onMouseOver="affichage('vente');" onMouseOut="affichage2('vente');"><a href="php/vente_art.php">Ventes d'aricle</a></span><br/><br/>
<span id="achat" onMouseOver="affichage('achat');" onMouseOut="affichage2('achat');"><a href="php/achat_art.php">achats fournisseurs</a></span><br/><br/>
<span id="stock" onMouseOver="affichage('stock');" onMouseOut="affichage2('stock');"><a href="php/stockmanif.php">Stock Manifestation</a></span><br/><br/>
<span id="fiche" onMouseOver="affichage('fiche');" onMouseOut="affichage2('fiche');"><a href="php/stock.php">Fiche de stock</a></span><br/><br/>
<span id="client" onMouseOver="affichage('client');" onMouseOut="affichage2('client');"><a href="php/clients.php">Liste des clients</a></span><br/><br/>
<span id="fourn" onMouseOver="affichage('fourn');" onMouseOut="affichage2('fourn');"><a href="">Liste des fournisseurs</a></span>
</div>
<div id="centre">
<FORM method="post" action="">
<FIELDSET>
<LEGEND align=top> <b>Créer un article</b> </LEGEND><br>
<u>Code</u> : <INPUT name="code" type="text" size="40">
<u>Designation</u> : <INPUT name="designation" type="text" size="40"><br><br>
<u>Type</u> : <SELECT name="type">
<OPTION VALUE="manches courtes">Manches courtes </OPTION>
<OPTION VALUE="manches longues">Manches longues</OPTION>
</SELECT>
<u>Couleur</u> : <SELECT name="couleur">
<OPTION VALUE="bleu marine">Bleu marine</OPTION>
<OPTION VALUE="blanc">Blanc</OPTION>
</SELECT><br><br>
<u>Taille</u> : <SELECT name="taille">
<OPTION VALUE="S">S</OPTION>
<OPTION VALUE="M">M</OPTION>
<OPTION VALUE="L">L</OPTION>
<OPTION VALUE="XL">XL</OPTION>
<OPTION VALUE="XXL">XXL</OPTION>
<OPTION VALUE="XXXL">XXXL</OPTION>
</SELECT>
<u>Prix</u> : <INPUT name="prix" type="text" size="40">
<u>Quantité</u> : <INPUT name="qte" type="text" size="40"><br><br>
<input type="submit" name="valider" value="Ajouter" />
<input type="submit" name="new" value="Nouveau" /><br/><br/>
</FIELDSET>
</FORM>
</div>
</div>
</body>
</html>
A+
Je déconseille la fonction extract() : n'importe quel personne mal intentionnée peut facilement modifier le formulaire, donc y ajouter ces propre champs, avec le nom d'une variable qu'il pourrait donc modifier.
Pour le problème :
Pour le problème :
<?php
include("login.php");
$connexion=mysql_connect("$db_host","$db_log","$db_pwd");
mysql_select_db($db_name) or die ("problème de connexion");
$code = $_POST['code'];
$designation = $_POST['designation'];
$type = $_POST['type'];
$couleur = $_POST['couleur'];
$taille = $_POST['taille'];
$prix = $_POST['prix'];
$qte = $_POST['qte'];
// ...Tu fais appeles aux variables $_POST['code'], $_POST['designation'], ... sans même vérifier si elles existent. Utilise la fonction isset() qui retourne true si la variable passée en premier argument est définie (is set).
Imagine que tu aies une variable $maxUploadSize qui contient la taille maximum autorisée en octect des fichiers uploadés via un formulaire.
Une personne mal-intentionnée pourrait ajouter un champ ayant "maxUploadSize" comme name (c'est facilement faisable : Sous Firefox, avec Firebug, sous Chrome avec les outils de développement intégrés) :
Avec la fonction extract($_POST), $maxUploadSize sera réécrite car il existe une clée "maxUploadSize" dans l'array $_POST.
Pour tester :
Forcément il faut connaître le nom de la variable, mais, par exemple, si tu vois qu'un site a été réalisé avec le tutoriel du SdZ, le codeur a certainement utilisé les mêmes nom de variables. Ou bien alors tu peux tester plus nom différents.
Une personne mal-intentionnée pourrait ajouter un champ ayant "maxUploadSize" comme name (c'est facilement faisable : Sous Firefox, avec Firebug, sous Chrome avec les outils de développement intégrés) :
<input type="hidden" name="maxUploadSize" value="99999999999" />
Avec la fonction extract($_POST), $maxUploadSize sera réécrite car il existe une clée "maxUploadSize" dans l'array $_POST.
Pour tester :
<?php $maxUploadSize = 1048576; // 1Mo echo 'Variable $maxUploadSize avant extract() : '.$maxUploadSize.'<br/>'; extract($_GET); echo 'Variable $maxUploadSize après extract() : '.$maxUploadSize.'<br/>' . '<br/>' . 'Pour modifier la variable, ajoutez « ?maxUploadSize=<em>valeur</em> » à la fin de l\'url.<br/>'; ?>Ici, je le fais avec $_GET mais ça fonctionne aussi avec $_POST.
Forcément il faut connaître le nom de la variable, mais, par exemple, si tu vois qu'un site a été réalisé avec le tutoriel du SdZ, le codeur a certainement utilisé les mêmes nom de variables. Ou bien alors tu peux tester plus nom différents.