[AJAX] output mysql de fonctions ajax listes déroulantes liés qui n'est pas detecté
ce code me permet de lier 3 listes déroulantes et il est fonctionnel (regardez photo pièce jointe) le problème est que l'output qui consiste dans code_typ_mat_pre (regardez le script pour couleur_mat_pre.php) n'est pas detecté dans ma page d'insertion de requête!
voici le script de la page principal et l'imprime écran et dans les pièces jointes
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| <?php session_start();
include("dynamique/connect.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
//fonction listes déroulantes lié 1
<script language="JavaScript">
function liste_mat_pre(f,i)
{
liste1 ="mat_pre"+i;
liste2 ="des_typ_pre"+i;
var l1=f.elements[liste1];
var l2=f.elements[liste2];
var index = l1.selectedIndex;
if(index<1)
l2.options.length=0;
else
{
var xhr_object = null;
if(window.XMLHttpRequest) xhr_object=new XMLHttpRequest();
else if(window.ActiveXObject)
{
xhr_object= new ActiveXObject("Microsof.XMLHTTP");
}
else
{
alert("votre navigateur ne supporte pas les objects XMLHTTPxhr_objectREQUEST....");
return;
}
xhr_object.open("POST", "typ_mat_pre.php", true);
xhr_object.onreadystatechange=function(){
if(xhr_object.readyState==4)
eval(xhr_object.responseText);
}
xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var data="champ="+escape(l1.options[index].value)+"&form="+f.name+"&select="+escape(liste2);
xhr_object.send(data);
}
}
//fonction liste déroulante liés 2 même concept que la première
function liste_col_pre(c,j)
{
list1 ="des_typ_pre"+j;
list2 ="couleur"+j;
var m1=c.elements[list1];
var m2=c.elements[list2];
var index = m1.selectedIndex;
if(index<1)
m2.options.length=0;
else
{
var xhr = null;
if(window.XMLHttpRequest) xhr=new XMLHttpRequest();
else if(window.ActiveXObject)
{
xhr= new ActiveXObject("Microsof.XMLHTTP");
}
else
{
alert("votre navigateur ne supporte pas les objects XMLHTTPxhr_objectREQUEST....");
return;
}
xhr.open("POST", "couleur_mat_pre.php", true);
xhr.onreadystatechange=function(){
if(xhr.readyState==4)
eval(xhr.responseText);
}
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var data="champ="+escape(m1.options[index].value)+"&form="+c.name+"&select="+escape(list2);
xhr.send(data);
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>insertion quantité de matières premières utilisés</title>
<style type="text/css">
<!--
.Style1 {
font-size: 18px;
font-weight: bold;
}
-->
</style>
</head>
<body bgcolor="#00FFFF" text="#000000" vlink="#FF00FF" alink="#FFFFFF">
//les listes déroulantes en cases de tableau aucun problème elles sont fonctionnels
<form action="dynamique/dynamique-formu4.php" method="post" name="form" id="form">
<span class="Style1">Table matières premières</span>
<table width="550">
<tr>
<td width="192"><div align="center">Matière première </div></td>
<td width="192"><div align="center">DéSIGNATION</div></td>
<td width="144"><div align="center">couleur</div></td>
<td width="144"><div align="center">QTE</div></td>
</tr>
<tr>
<td width="201"><select name="mat_pre1" id="mat_pre1" onchange="liste_mat_pre(this.form,1);">
<option value="0">Choisir une matière première</option>
<?php
$req="SELECT * FROM matiere_premiere where des_mat_pre!='tissus' ORDER BY des_mat_pre";
$resreq= mysql_query($req) or die(mysql_error());
while($lisdr=mysql_fetch_assoc($resreq))
{
?>
<option value="<?php echo $lisdr['code_mat_pre']; ?>"><?php echo $lisdr['des_mat_pre']; ?></option>
<?php
}
?>
</select></td>
<td width="91"><select name="des_typ_pre1" id="des_typ_pre1" onchange="liste_col_pre(this.form,1)">
<option value="0">-type matière-</option>
</select></td>
<td width="127"><select name="couleur1" id="couleur1" >
<option value="0">- sa couleur-</option>
</select></td>
<td width="111"><input type="text" name="qte-mat-pre1" id="qte-mat-pre1" /></td>
</tr>
<tr>
<td width="201"><select name="mat_pre2" id="mat_pre2" onchange="liste_mat_pre(this.form,2);">
<option value="0">Choisir une matière première</option>
<?php
$req="SELECT * FROM matiere_premiere where des_mat_pre!='tissus' ORDER BY des_mat_pre";
$resreq= mysql_query($req) or die(mysql_error());
while($lisdr=mysql_fetch_assoc($resreq))
{
?>
<option value="<?php echo $lisdr['code_mat_pre']; ?>"><?php echo $lisdr['des_mat_pre']; ?></option>
<?php
}
?>
</select></td>
<td width="91"><select name="des_typ_pre2" id="des_typ_pre2" onchange="liste_col_pre(this.form,2)"><option value="0">-type matière-</option>
</select></td>
<td width="127"><select name="couleur2" id="couleur2" ><option value="0">- sa couleur-</option>
</select></td>
<td width="111"><input type="text" name="qte-mat-pre2" id="qte-mat-pre2" /></td>
</tr>
<tr>
<td width="201"><select name="mat_pre3" id="mat_pre3" onchange="liste_mat_pre(this.form,3);">
<option value="0">Choisir une matière première</option>
<?php
$req="SELECT * FROM matiere_premiere where des_mat_pre!='tissus' ORDER BY des_mat_pre";
$resreq= mysql_query($req) or die(mysql_error());
while($lisdr=mysql_fetch_assoc($resreq))
{
?>
<option value="<?php echo $lisdr['code_mat_pre']; ?>"><?php echo $lisdr['des_mat_pre']; ?></option>
<?php
}
?>
</select></td>
<td width="91"><select name="des_typ_pre3" id="des_typ_pre3" onchange="liste_col_pre(this.form,3)"><option value="0">-type matière-</option>
</select></td>
<td width="127"><select name="couleur3" id="couleur3" ><option value="0">- sa couleur-</option>
</select></td>
<td width="111"><input type="text" name="qte-mat-pre3" id="qte-mat-pre3" /></td>
</tr>
... |
et voici le script de la page couleur_mat_pre.php je l'ai mis parce que quand même j'ai un doute la concernant malgré que les listes déroulantes liés s'affiche bien le champs appelant à cette fonction .$_POST["$couleur"]. quand je l'ai mis en echo n'a pas voulu afficher son contenu comme vous allez le remarquez!
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <? session_start();
header('Content-Type: text/html; charset=iso-8859-1');
include("dynamique/connect.php");
$res = mysql_query("SELECT * FROM type_matiere_premiere WHERE code_typ_mat_pre='".$_POST["champ"]."' ORDER BY couleur");
echo 'var o = null;';
echo 'var s = document.forms["'.$_POST["form"].'"].elements["'.$_POST["select"].'"];';
echo 's.options.length=0;';
echo 's.options[s.options.length]=new Option("","0");';
while($row = mysql_fetch_assoc($res)){
echo 's.options[s.options.length]= new Option("'.$row["couleur"].'","'.$row["code_typ_mat_pre"].'");';
}
mysql_close();
?> |
et voici la requête d'insertion ou le problème subsiste
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?php session_start();
include("connect.php");
//n_art variable session aucun rapport avec mon problème
$n_art=$_SESSION['n_art'];
//traitement pour 6 ligne du tableau...
for($i=1;$i<6;$i++){
$qte=$_POST['$qte-mat-pre'.$i];
$code=$_POST["$couleur".$i];
echo "$code";
if($_POST["$couleur".$i]!='0')
{
$req_mat_pre="Select * from type_matiere_premiere,entree_stock where code_typ_mat_pre='".$_POST['$couleur'.$i]."'";
echo "$req_mat_pre";
$res= mysql_query($req_mat_pre) or die(mysql_error());
while($tabmatpre=mysql_fetch_assoc($res)){
$qtenstock=$tabmatpre['$qte_stock'];
}
$sous_qte_pre=$qtenstock-$qte;
if($sous_qte_pre<0)
{
echo "la quantité soustraite en {$tabmatpre['des_typ_mat_pre']} de la ligne $i n'est pas dans la capacité du stock";
}
$requete="UPDATE entree_stock SET qte_stock='$sous-qte-pre' where code_typ_mat_pre='".$_POST['$couleur'.$i]."'";
$result=mysql_query($requete)OR die(mysql_error());
$req="insert into consommer (n_art,code_typ_mat_pre,qte_mat_pre) values(".$n_art.",".$_POST['$couleur'.$i].",".$qte.")";
$result2=mysql_query($req)OR die(mysql_error());
}
}
mysql_close();
?> |
en effet le echo de .$_POST['$couleur'.$i]. ne donne rien et en plus voici le message d'erreur qui s'affiche
Code:
Select * from type_matiere_premiere,entree_stock where code_typ_mat_pre=''Champ: 'code_typ_mat_pre' dans where clause est ambigu
merci pour votre aide!!