3 liste deroulantes lies

Fermé
dahdah - 7 mai 2016 à 11:40
jordane45 Messages postés 38364 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 30 décembre 2024 - 9 mai 2016 à 15:31
Bonjour,
aide moi svp
voila je veux realiser 3 listes lies en php avec dreamweaver
1- avec 2 liste j'ai reussi
2-avec 3 liste il mo don ce message
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
voila le code de l app (grade.matiere.diplom)
<?php require_once('Connections/ccon.php'); ?>
<?php
mysql_select_db($database_ccon, $ccon);
$query_grad = "SELECT * FROM grade";
$grad = mysql_query($query_grad, $ccon) or die(mysql_error());
$row_grad = mysql_fetch_assoc($grad);
$totalRows_grad = mysql_num_rows($grad);

$colname_mat = "-1";
if (isset($_POST['cod_Grad'])) {
$colname_mat = (get_magic_quotes_gpc()) ? $_POST['cod_Grad'] : addslashes($_POST['cod_Grad']);
}
mysql_select_db($database_ccon, $ccon);
$query_mat = sprintf("SELECT cod_Mat, libele FROM matiere WHERE cod_Grad = %s", $colname_mat);
$mat = mysql_query($query_mat, $ccon) or die(mysql_error());
$row_mat = mysql_fetch_assoc($mat);
$totalRows_mat = mysql_num_rows($mat);

$colname_diplo = "-1";
if (isset($_POST['cod_Dip'])) {
$colname_diplo = (get_magic_quotes_gpc()) ? $_POST['cod_Dip'] : addslashes($_POST['cod_Dip']);
}
mysql_select_db($database_ccon, $ccon);
$query_diplo = sprintf("SELECT cod_Dip, libele FROM diplomes WHERE cod_Dip = %s", $colname_diplo);
$diplo = mysql_query($query_diplo, $ccon) or die(mysql_error());
$row_diplo = mysql_fetch_assoc($diplo);
$totalRows_diplo = mysql_num_rows($diplo);
?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="cod_Grad" id="cod_Grad" onchange="submit()">
<option value="" <?php if (!(strcmp("", $_POST['cod_Grad']))) {echo "selected=\"selected\"";} ?>>label</option>
<?php
do {
?>
<option value="<?php echo $row_grad['cod_Grad']?>"<?php if (!(strcmp($row_grad['cod_Grad'], $_POST['cod_Grad']))) {echo "selected=\"selected\"";} ?>><?php echo $row_grad['libele']?></option>
<?php
} while ($row_grad = mysql_fetch_assoc($grad));
$rows = mysql_num_rows($grad);
if($rows > 0) {
mysql_data_seek($grad, 0);
$row_grad = mysql_fetch_assoc($grad);
}
?>
</select>
</label>
<label>
<select name="cod_Mat" id="cod_Mat" onchange="submit()" >
<option value="" <?php if (!(strcmp("", $_POST['cod_Mat']))) {echo "selected=\"selected\"";} ?>>label</option>
<?php
do {
?><option value="<?php echo $row_mat['cod_Mat']?>"<?php if (!(strcmp($row_mat['cod_Mat'], $_POST['cod_Mat']))) {echo "selected=\"selected\"";} ?>><?php echo $row_mat['libele']?></option>
<?php
} while ($row_mat = mysql_fetch_assoc($mat));
$rows = mysql_num_rows($mat);
if($rows > 0) {
mysql_data_seek($mat, 0);
$row_mat = mysql_fetch_assoc($mat);
}
?>
</select>
</label>
<label></label>
<label>
<select name="cod_Dip" id="cod_Dip">
<?php
do {
?><option value="<?php echo $row_diplo['cod_Dip']?>"<?php if (!(strcmp($row_diplo['cod_Dip'], $_POST['cod_Dip']))) {echo "selected=\"selected\"";} ?>><?php echo $row_diplo['libele']?></option>
<?php
} while ($row_diplo = mysql_fetch_assoc($diplo));
$rows = mysql_num_rows($diplo);
if($rows > 0) {
mysql_data_seek($diplo, 0);
$row_diplo = mysql_fetch_assoc($diplo);
}
?>
</select>
</label>
</form>
</body>
</html>
<?php
mysql_free_result($grad);

mysql_free_result($mat);

mysql_free_result($diplo);
?>
A voir également:

1 réponse

jordane45 Messages postés 38364 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 30 décembre 2024 4 720
9 mai 2016 à 15:31
Bonjour,

1 - Merci de mettre les balises de code
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code

2 - Tu utilises encore l'ancienne extension mysql (considérée comme obsolète).
https://www.commentcamarche.net/faq/43261-php-l-extension-mysql-est-obsolete#top
Tu devrais passer à PDO ou mysqli

3 - Fais un ECHO de la requête qui te pose problème ... et teste la directement dans ta BDD pour voir où se trouve l'erreur.
0