Page 1 sur 2

Problème d' INSERT

Posté : 05 févr. 2007, 18:02
par jenny06
Bonjour,

je vous explique ma situation. J'ai une table catégorie qui contient :
-idCategorie
-nomCategorie
-nomSousCategorie

j'ai créer un formulaire ajout de categorie, il marche très bien. J'ai voulu créer un formulaire "ajout de sous categorie" il ne marche pas.

Voici l'erreur :
Notice: Undefined variable: idCategorie in c:\jennifer\easyphp1-8\www\aadena.net\extranet\insertsouscategorie.php on line 8

Problème lors de l'enregistrement

INSERT INTO categorie (nomSousCategorie) values ('bouh') where idCategorie=''
Voici mon code :
<?php
//require("include/secure.php");
//require("include/comvar.php");
include_once("include/secure.php");
include_once("include/comvar.php");

if (isset($submit)){
$sql ="INSERT INTO categorie (nomSousCategorie) values ('$nomSousCategorie') where idCategorie='$idCategorie'";
//$sql ="UPDATE categorie SET nomSousCategorie='$nomSousCategorie' WHERE idCategorie='$idCategorie'";
if ($result = mysql_query($sql)) {
header("Location:adminCategorie.php");		
	}
	else {
		echo "<BR>Problème lors de l'enregistrement<BR><BR>";
		echo $sql;
	}
}
?>

<html>
<head>
<link href="CSS/ADENA1.css" rel="stylesheet" type="text/css">
<link href="CSS/ADENA3.css" rel="stylesheet" type="text/css">
<link href="CSS/Nouveau%20dossier.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" bgcolor="#FFFFFF">
<table width="101%" height="74" border="0" cellpadding="0" cellspacing="0" class="ADENA4">
  <tr> 
    <td width="18%" height="74" class="TITRE"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="186" height="74">
        <param name=movie value="images/adena.swf">
        <param name=quality value=high>
        <embed src="images/adena.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="186" height="74"> 
        </embed> </object> </td>
    <td width="82%" class="TITRE"><b>Insertion 
      d'une nouvelle sous categorie</b><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
  </tr>
</table><br>
<table width="973" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="1255" height="30" align="center" valign="middle" class="ggg"><a href="index.php" class="ggg">Menu 
      Général</a> </td>
  </tr>
</table>

 
<center>
  <BR>
</center>
<form method="post" action="<?php echo "$PHP_SELF"?>">
  <table width="900" border="0" cellspacing="0" cellpadding="0" background="" align="center">
    <tr> 
      <td>&nbsp;</td>
      <td width="900" colspan="2"> <table width="100%" border="1" cellspacing="0">
          <!--<tr> 
            <td width="300" align="center" bgcolor="#81ADC8" class="ADENA5"><b><font color="#FFFFFF" face="Arial, Helvetica, sans-serif" size="2">Categorie</font></b></td>
            <td bgcolor="#FFFFFF" align="left" width="300"> <div align="left"><font color="#FFFFFF" size="2"><b><font face="Arial, Helvetica, sans-serif"> 
                <input type="text" size="50" name="nomCategorie">
                </font></b></font></div></td>
          </tr>-->
		  <tr> 
            <td width="300" align="center" bgcolor="#81ADC8" class="ADENA5"><b><font color="#FFFFFF" face="Arial, Helvetica, sans-serif" size="2">Sous Categorie</font></b></td>
            <td bgcolor="#FFFFFF" align="left" width="300"> <div align="left"><font color="#FFFFFF" size="2"><b><font face="Arial, Helvetica, sans-serif"> 
                <input type="text" size="50" name="nomSousCategorie">
                </font></b></font></div></td>
          </tr>
          <tr bgcolor="#669ACC"> 
            <td colspan="2" align="center"> <font color="#FFFFFF" size="2"><b><font face="Arial, Helvetica, sans-serif"> 
              <input type="submit" name="submit" value="Valider">
              </font></b></font><font size="2">&nbsp;</font></td>
          </tr>
        </table></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td height="20" bgcolor="#669ACC" > <div align="center" class="ADENA"><font size="2"><b><a href="../index.php" class="ADENA">Direction 
          site public</a></b></font></div></td>
      <td height="20" bgcolor="#669ACC" > <div align="center" class="ADENA"><font size="2"><b><a href="index.php" class="ADENA">Direction 
          panneau d'Administration</a></b></font></div></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  </form>
</body>

</html>

Merci d'avance de votre aide. N'hésité pas a me demander plus de renseignement.

Jenny

Posté : 05 févr. 2007, 18:14
par mere-teresa
Heu d'où vient ta variable $idCategorie ? Du formulaire ? De la session ? D'un fichier inclus au dessus ?

$sql ="INSERT INTO categorie (nomSousCategorie) values ('$nomSousCategorie') where idCategorie='$idCategorie'";

Posté : 05 févr. 2007, 18:18
par jenny06
Il vient du fichier d'avant je suppose.

En faite j'ai un formulaire de base qui contient un bouton et lorsqu'on clique dessus, on rentre sur le formulaire que je vous ai envoyer au dessus


Voici le fichier de base :
<?
require("include/secure.php");
require("include/comvar.php");

//include("include/inversionDate.inc.php");

$strSQL="SELECT * FROM categorie order by idCategorie desc, nomCategorie desc";
$result = mysql_query($strSQL);

?>

<html>
<head>
<title>Gestion des Categories / Sous-Categories</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT langage="javascript">
<!--
function etesVousSure(arg){

aux=confirm("Voulez vous vraiment supprimer cette categorie");

if (aux) {
str ="supprimerCategorie.php?idCategorie="+arg;
MM_goToURL("self", str);
};
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>
<link href="CSS/ADENA1.css" rel="stylesheet" type="text/css">
<link href="CSS/Nouveau%20dossier.css" rel="stylesheet" type="text/css">
</head>

<link rel="stylesheet" href="perseX.css" type="text/css">
<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">
<table width="101%" height="74" border="0" cellpadding="0" cellspacing="0" class="ADENA4">
  <tr> 
    <td width="18%" height="74" class="TITRE"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="186" height="74">
        <param name=movie value="images/adena.swf">
        <param name=quality value=high>
        <embed src="images/adena.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="186" height="74"> 
        </embed> </object> </td>
    <td width="82%" class="TITRE">Gestion des Categories / Sous-Categories</td>
  </tr>
</table>
<p> 
<table width="973" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="1883" height="40
	" align="center" valign="middle" class="ggg"><a href="index.php" class="ggg">Menu 
      Général</a> </td>
  </tr>
  <tr> 
    <td width="1255" height="40" align="center" valign="middle" class="ADENA"> 
      <div align="center"><img src="images/deco.jpg" width="970" height="40"></div></td>
  </tr>
  <tr> 
    <td height="40" align="center" valign="middle" bordercolor="#FFFFFF" bgcolor="#669ACC"> 
	<form name="lien" action="insertCategorie.php" method="post">
	<input type="submit" name="link" value="Ajouter une Categorie" class="bouton"> 
    </form>      
    </td>
  </tr>
</table>

<!-- MISE EN FORME -->
<table align="center" bordercolor="#425065" border=1 cellpadding="0" cellspacing="0">
    <td height="159" valign="middle" bordercolor="#FFFFFF" bgcolor="#669ACC"> 
      <!-- MISE EN FORME -->
      <table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#669ACC">
        <tr class="spe"> 
          <td width="175" height="20" colspan="2"> 
            <div align="center" class="ADENA"><b>Categorie</b></div>
          </td>
          <td width="350" height="20" colspan="3"> 
            <div align="center" class="ADENA"><b>Traitement</b></div>
          </td>
        </tr>
        <?
while ($myrow = mysql_fetch_array($result)) {
?>
        <tr> 
          <td width="80" height="58" bgcolor="#81ADC8" colspan="2"> 
            <div align="center" class="ggg" ><b><font size="2"> 
              <? 
           	   printf("%s", $myrow["nomCategorie"]);
              ?>
              </b></div>
          </td>
          <!--<td width="320" height="58" bgcolor="#FFFFFF" bg> 
            <div align="left" class="ggg"><b><font size="2"> 
              <? 
           	  // printf("%s", $myrow["nomSousCategorie"]);
              ?>
              </b></div>
          </td>-->
          <td height="48" bgcolor="#FFFFFF"> 
            <div align="center"><a href="<?php printf("editCategorie.php?idCategorie=%s", $myrow["idCategorie"])?>"> 
              </a><a href="#"><img src="images/modifier.gif" width="24" height="31" border="0" onClick="MM_goToURL('self', 'editCategorie.php?idCategorie=<?php printf("%s", $myrow["idCategorie"])?>')" alt="Modifier la Categorie"></a></div>
          </td>
          <td height="48" bgcolor="#FFFFFF"> 
            <div align="center"><a href="javascript:etesVousSure(<?php printf("%s", $myrow["idCategorie"]); ?>)"> 
              </a><a href="#"><img src="images/supprimer.gif" width="24" height="31" border="0" onClick="MM_callJS('etesVousSure(<?php printf("%s", $myrow["idCategorie"]); ?>)')" alt="Supprimer la Categorie"></a></div>
          </td>
		  <td height="48" bgcolor="#FFFFFF"> 
            <div align="center"><form name="lien" action="insertSousCategorie.php" method="post">
			<input type="submit" name="link" value="Ajouter une Sous Categorie" class="bouton"> 
			</form>
			</div>
          </td>
        </tr>
		<?
		if($myrow["nomSousCategorie"]!='')
		{?>
			<tr>
			<td width="80">&nbsp;</td>
			
			<td width="80" height="58" bgcolor="#81ADC8"> 
            <div align="center" class="ggg"><b><font size="2"> 
              <? 
           	   printf("%s", $myrow["nomSousCategorie"]);
              ?>
              </b></div>
          </td>
          <!--<td width="320" height="58" bgcolor="#FFFFFF" bg> 
            <div align="left" class="ggg"><b><font size="2"> 
              <? 
           	  // printf("%s", $myrow["nomSousCategorie"]);
              ?>
              </b></div>
          </td>-->
          <td height="48" bgcolor="#FFFFFF"> 
            <div align="center"><a href="<?php printf("editCategorie.php?idSousCategorie=%s", $myrow["idSousCategorie"])?>"> 
              </a><a href="#"><img src="images/modifier.gif" width="24" height="31" border="0" onClick="MM_goToURL('self', 'editSousCategorie.php?nomCategorie=<?php printf("%s", $myrow["idCategorie"])?>')" alt="Modifier la Sous Categorie"></a></div>
          </td>
          <td height="48" bgcolor="#FFFFFF"> 
            <div align="center"><a href="javascript:etesVousSure(<?php printf("%s", $myrow["idSousCategorie"]); ?>)"> 
              </a><a href="#"><img src="images/supprimer.gif" width="24" height="31" border="0" onClick="MM_callJS('etesVousSure(<?php printf("%s", $myrow["idCategorie"]); ?>)')" alt="Supprimer la Sous Categorie"></a></div>
          </td>
			</tr>
		<?php }
    }
			?>
	   </table>
	  <br>
    </td>
</table>
<br>
<center>
  <table width="973" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="1883" height="40" align="center" valign="middle" class="ggg">
	  <a href="index.php" class="ggg">Menu Général</a> </td>
    </tr>
  </table>
</center>
</body>
</html>
Vous comprenez mieux ?

Posté : 05 févr. 2007, 19:29
par mere-teresa
Il vient du fichier d'avant je suppose.
Heu il ne faut pas supposer, là, c'est ton code. Tu le maîtrises plus ou moins, mais cette variable manque à l'appel et fait planter ta requête.
Telle Inspecteur Gadget, pars à la recherche de l'affectation de cette variable dans ton code.

Posté : 06 févr. 2007, 11:15
par jenny06
Tu le maîtrises plus ou moins, mais cette variable manque à l'appel et fait planter ta requête.
je le sais bien. c'est pour cela que je demande de l'aide.

Posté : 06 févr. 2007, 11:28
par Dom!
Je note une chose qui peut parraître bête mais tu as 2 formulaire qui porte le même nom est ce normal ?

:?:

Posté : 06 févr. 2007, 11:34
par jenny06
Il est vrai que c'est une chose, en fesant copier coller que je n'ai pas fait attention. Je l'ai modifier mais ca ne change rien, j'ai toujours la même erreur

Merci quand même :D

Posté : 06 févr. 2007, 17:47
par Invité
Personne a une petite idée pour mon problème :D

Posté : 06 févr. 2007, 17:49
par jenny06
Excusez moi pour le message au dessus je n'avais pas remarquer que je n'était pas connecté.

Merci

Posté : 12 févr. 2007, 11:37
par jenny06
Bonjour,

Personne n'a toujours pas d'idée qui pourrait m'éclaircir ?


Merci,

Posté : 12 févr. 2007, 11:44
par Ryle
Modération :
jenny06, les "up" sont interdits sur PHPFrance.

Si tu n'as pas obtenu de réponse, c'est (au choix) :
- que ta question est mal formulée : reformule-la différemment ;
- que personne ne connaît la réponse ici : faire un "up" ne te donnera pas davantage de résultats ;
- que la réponse demandée exige un travail important que personne ne va faire à ta place ;
[/b][/url].


As-tu essayé de suivre les conseils de mere-teresa et de retrouver l'origine de ta variable ?

Posté : 12 févr. 2007, 11:53
par jenny06
oui j'ai essayer de suivre les conseils, sinon j'aurai pas continuer à demander de l'aide et non pas de me faire mon script.

Posté : 12 févr. 2007, 12:59
par Ryle
Et qu'en est-il alors de cette variable ? :)


Bon ceci, tron problème provient très certainement de l'utilisation d'une clause WHERE dans une requête de type INSERT. Soit tu fais une insertion pour créer une nouvelle ligne - et il n'y a donc pas de condition where, tu insères et pis c'est tout ;) - soit tu fais un update pour mettre à jour une (ou plusieurs) ligne(s) et dans ce cas là, tu peux éventuellement utiliser la clause where pour spécifier quelles lignes tu mets à jour...

Y a pas de mélange des deux ;)

Posté : 12 févr. 2007, 15:08
par jenny06
d'accord merci, je vais essayer ca :D

Posté : 13 févr. 2007, 10:47
par jenny06
Bonjour,


Je crois avoir trouver mon problème :
j'ai rajouter une table sous catégorie qui contient :

-idSousCategorie
-idCategorie
-nomSousCategorie

mais voilà j'ai un deuxième problème, je n'arrive pas a mettre idCategorie ds cette table comme clé étrangère et à faire le lien avec ma première table :(

merci :D