Connexion base de données

Eléphanteau du PHP | 16 Messages

15 mai 2012, 09:34

Bonjour,

Je suis actuellement stagiaire en informatique dans un collège, et je dois transférer un site internet d'un serveur à un autre.
J'ai réussi à faire fonctionner la plupart des modules et j'ai déjà demandé de l'aide sur ce forum et cela m'a été très bénéfique. Voilà pourquoi je me tourne à nouveau vers vous pour vous faire part d'un problème que je rencontre.

Tous mes modules fonctionnent correctement sauf un.
Je n'arrive pas à récupérer les données de la base de données alors que la connexion se fait bien...

Je vous joint le code... J'ai déjà fait beaucoup de modification car le code n'était plus tellement d'actualité.

Merci d'avance.


Fichier 1 : Index2.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Classe & &eacute;quipe p&eacute;dagogique</title>
</head>

<frameset rows="175,*" cols="*" framespacing="0" frameborder="NO" border="0">
  <frame src="haut.php?id_niveau=<?php echo "$id_niveau"; ?>" name="topFrame" scrolling="NO" noresize>
  <frame src="bas.php" name="mainFrame">
</frameset>
<noframes><body>
</body></noframes>
</html>
Fichier 2 : haut.php
<style type="text/css">
<!--
.Style1 {
	color: #000000;
	font-weight: bold;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.Style2 {
	color: #FFCC00;
	font-weight: bold;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
a:link {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: medium;
	font-style: oblique;
	color: #0099FF;
}
a:visited {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: medium;
	font-style: oblique;
	color: #0099FF;
}
-->
</style>
<?php
$id_connect=mysql_connect("mon_serveur","mon_identifiant","mon_mot_de_passe") or die ("probleme de connexion");
mysql_select_db("ma_bdd") or die ("probleme de BDD");
mysql_query("SET NAMES 'utf8'");


	echo "<table border='0' width='273' cellspacing='0' cellpadding='0' align='center'><tr>
<table border='0' width='50' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td width='10' valign='top'><img border='0' src='CLT.gif' width='10' height='10'></td>
    <td width='249' valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
    <td width='10' valign='top'><img border='0' src='CRT.gif' width='10' height='10'></td>
  </tr>
  <tr>
    <td valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
    <td valign='top' bgcolor='#DFE3EB'><p align='center' class='Style1'>$id_niveau &deg;</a></p>      </td>
    <td valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
  </tr>
  <tr>
    <td height='10' valign='top'><img border='0' src='CLD.gif' width='10' height='10'></td>
    <td valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
    <td valign='top'><img border='0' src='CRD.gif' width='10' height='10'></td>
  </tr>
</table></td></tr></table>";

echo "<table border='0' width='273' cellspacing='0' cellpadding='0' align='center'><tr>";

$sql2=" SELECT * FROM classe WHERE id_niveau = '$id_niveau' ";
$req2 = mysql_query($sql2) or die("Erreur SQL !<br>$sql2<br>mysql_error()"); 
echo "<hr width='100%' color='red'>";
while($field2 = mysql_fetch_array($req2))
{
	echo "<td><table border='0' width='130' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td colspan='3' valign='top'><div align='center'><img src='fleche_b.gif'></div></td>
  </tr>
  <tr>
    <td colspan='3' valign='top'><div align='center'><img src='fleche_b.gif'></div></td>
  </tr>
  <tr>
    <td width='10' valign='top'><img border='0' src='CLT.gif' width='10' height='10'></td>
    <td width='249' valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
    <td width='10' valign='top'><img border='0' src='CRT.gif' width='10' height='10'></td>
  </tr>
  <tr>
    <td valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
    <td valign='top' bgcolor='#DFE3EB'><p align='center'><a href='bas.php?id_classes=$field2[0]&classe_user=$field2[3]' target='mainFrame' class='Style3'>$field2[3]</a></p>      </td>
    <td valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
  </tr>
  <tr>
    <td height='10' valign='top'><img border='0' src='CLD.gif' width='10' height='10'></td>
    <td valign='top' bgcolor='#DFE3EB'><img border='0' src='1px.gif' width='10' height='10'></td>
    <td valign='top'><img border='0' src='CRD.gif' width='10' height='10'></td>
  </tr>
</table></td>";
}

echo "</tr></table>";
?>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100" height="23">
  <param name="movie" value="button1.swf">
  <param name="quality" value="high">
  <embed src="button1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100" height="23"></embed>
</object>

Fichier 3:Bas.php
<style type="text/css">

<!--
.Style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #0066CC;
}
.Style4 {color: #003366; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; }
.Style7 {color: #003366; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small; }
.Style8 {color: #DFE3EB; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; }

.Style2 {
	font-size: 9px;
	font-weight: bold;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
<?php
if (isset($id_classes))
{
echo "<hr width='100%' color='bleu'>";
echo "<div align='center' class='Style1'>
  <br><h2>Equipe p&eacute;dagogique de la $classe_user</h2>
  <p>&nbsp;</p>
  <p><div align='center'>
  <table width='200' border='0'>
    <tr>
      <td width='15'><div align='center'><a href='javascript:window.print()'><img src='print.gif' width='16' height='16' border='0' alt='Imprimer'></a></div></td>
      <td width='169'><div align='left' class='Style2'>Imprimer cette page</div></td>
    </tr>
  </table>
</div></p>
</div>";

$id_connect=mysql_connect("mon_serveur","mon_identifiant","mon_mot_de_passe") or die ("probleme de connexion");
mysql_select_db("ma_bdd") or die ("probleme de BDD");
mysql_query("SET NAMES 'utf8'");



$sql=" select prof.nom_prof, prof.prenom_prof, prof.email_prof from classe, prof where classe.id_classes = '$id_classes' and classe.id_prof = prof.id_prof ";
$req = mysql_query($sql) or die("Erreur SQL !<br>$sql<br>mysql_error()"); 

while ($field = mysql_fetch_array($req))
{
	echo "<table width='600' border='0' align='center'>
  <tr bgcolor='#DFE3EB'>
    <td colspan='3'><div align='center' class='Style4'>Professeur principal</div></td>
  </tr>
  <tr bgcolor='#DFE3EB'>
    <td width='159'><div align='center' class='Style7'>Nom</div></td>
    <td width='129'><div align='center' class='Style7'>Pr&eacute;nom</div></td>
    <td width='298'><div align='center' class='Style7'>E-mail</div></td>
  </tr>
  <tr bgcolor='#003366'>
    <td><div align='center' class='Style8'>$field[0]</div></td>
    <td bgcolor='#003366'><div align='center' class='Style8'>$field[1]</div></td>
    <td><a href='mailto:$field[2]'><div align='center' class='Style8'>$field[2]</div></a></td>
  </tr>
</table><br>";
}

$sql2=" select prof.nom_prof, prof.prenom_prof, prof.email_prof, matiere.nom_matiere, membre_eq_ped.id_membre_eq from membre_eq_ped, prof, matiere, ass_prof_mat where membre_eq_ped.id_classes='$id_classes' and membre_eq_ped.id_ass_prof_mat = ass_prof_mat.id_ass_prof_mat and ass_prof_mat.id_prof = prof.id_prof and ass_prof_mat.id_matiere = matiere.id_matiere ORDER BY prof.nom_prof, prof.prenom_prof ";
$req2 = mysql_query($sql2) or die("Erreur SQL !<br>$sql2<br>mysql_error()"); 

echo "<table width='600' border='0' align='center'>
  <tr bgcolor='#DFE3EB'>
    <td width='111'><div align='center' class='Style7'>Nom</div></td>
    <td width='98'><div align='center' class='Style7'>Pr&eacute;nom</div></td>
    <td width='127'><div align='center' class='Style7'>Mati&egrave;re</div></td>
    <td width='246'><div align='center'><span class='Style7'>E-mail</span></div></td>
  </tr>";
  while ($field2 = mysql_fetch_array($req2))
  {
	echo "<tr bgcolor='#003366'>
    <td><div align='center' class='Style8'>$field2[0]</div></td>
    <td bgcolor='#003366'><div align='center' class='Style8'>$field2[1]</div></td>
    <td><div align='center' class='Style8'>$field2[3]</div></td>
    <td><div align='center'><a href='mailto:$field2[2]'><span class='Style8'>$field2[2]</span></a></div></td>
  </tr>";
  }
  echo "</table><br>";
  
$sql3=" select * from projet_classe where id_classes = '$id_classes' ";
$req3 = mysql_query($sql3) or die("Erreur SQL !<br>$sql3<br>mysql_error()"); 
$nbr = mysql_num_rows($req3);

echo "<table width='600' border='0' align='center'>
  <tr bgcolor='#DFE3EB'>
    <td><div align='center' class='Style7'>Projet(s) classe<span class='Style7'></span></div>      </td>
  </tr>";
if ($nbr == 0)
{
	echo "<tr bgcolor='#003366'>
    <td><div align='center' class='Style8'>Aucun projet enregistré pour le moment !</div></td>
  	</tr>
	</table>";
}
else if ($nbr > 0)
{
while ($field3 = mysql_fetch_array($req3))
{
	echo " <tr bgcolor='#003366'>
    <td bgcolor='#003366'><div align='center' class='Style8'>
      <p><u><strong>$field3[2]</strong></u></p>
      <p>$field3[4]</p>
    </div>      </td>
  </tr>
  <tr bgcolor='#003366'>
    <td bgcolor='#003366' class='Style8'><div align='left'><strong>Lien :</strong> $field3[3]</div></td>
  </tr>";
}
echo "</table>";
}
}

else
echo "<table width='500' height='350' border='0' align='center'>
  <tr>
    <td><img src='P1.3.jpg' width='622' height='358' align='absmiddle'></td>
  </tr>
</table>";

?>

ViPHP
ViPHP | 2577 Messages

15 mai 2012, 09:38

Il faudrait que tu sois plus précis dans ton problème. Message d'erreur, comportement...
Sans ca difficile de t'aider.

Eléphanteau du PHP | 16 Messages

15 mai 2012, 09:42

En fait, justement, je n'ai rien, ma page s'affiche mais aucune donnée n'est indiquée... Même pas de message d'erreur me disant "connexion impossible", rien ne se passe tout simplement, comme si il n'y avait rien dans la table de la base de données. (alors que si, j'ai tout vérifié).
D'où mon incompréhension.
D'habitude, j'ai au moins un message d'erreur... içi... Rien...

Eléphanteau du PHP | 16 Messages

15 mai 2012, 10:22

J'ai l’impression que c'est histoire de variables mais je n'en suis pas sûr à 100% j'ai beau analyser le code, j'ai même utiliser le debugger, et les seuls soucis qu'il m'indique sont des soucis de variables...

Eléphanteau du PHP | 16 Messages

15 mai 2012, 11:12

Voilà, j'ai mis en pièces jointes, ce que j'obtiens et ce que je devrais obtenir
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.

ViPHP
ViPHP | 2577 Messages

15 mai 2012, 11:33

Regarde le source html de ta page.

"...asses=$field2[0]&classe_user=$field2[3]' ..."
à remplacer par
"...asses=",$field2[0],"&classe_user=",$field2[3]"' ..."

Tu dois trouver $field2[0] et $field2[3] dans le source de ta page ou juste [0] et [3]. Les tableaux ne marche pas dans les chaines de caractères, il faut les sortir de la chaine.

Eléphanteau du PHP | 16 Messages

15 mai 2012, 12:48

Ah d'accord merci , mais est-ce que je dois aussi faire ça pour les requête SQL??
exemple : $sql2=" select * from ass_cycle_annee where id_cycle ='$field[0]' ";

ViPHP
ViPHP | 2577 Messages

15 mai 2012, 14:50

Oui.

Pour echo une virgule convient, mais pour les autres commandes, c'est un point pour concaténer des chaines de caractères.

Eléphanteau du PHP | 16 Messages

15 mai 2012, 15:04

Bon bah je ne comprends pas... j'ai bien effectuer les modifications que tu m'a indiqué mais rien n'a changé...

ViPHP
ViPHP | 2577 Messages

15 mai 2012, 18:45

Il faut regarder le source html pour voir ce qui est généré.
Si tu as un problème dans une boucle de lecture, tu peux ajouter des echo pour suivre le déroulement de ton script.

Vue que tu utilises des frames, tu peux travailler sur chaque partie séparément.