Problème dans mon code php
ennaoumi
Messages postés
18
Statut
Membre
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonsoir je fais une application web, et dans la page qui affiche l'historique j'ai plusieurs colonnes selon le nombre des champs de la base de donnée et parmi ces colonnes il a une icone qui me conduit vers la page qui me permet de modifier le contenu de mes champs, mais lorsque je clique sur l'icone, il me conduit vers une page blanche
voila la partie du code php de l'historique:
voila la partie du code php de l'historique:
<?php
include('connect.inc');
include('fonction.php');
// on crée la requête SQL
$sql = 'SELECT * FROM pfe.immobilisation';
// on envoie la requête
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
echo "<form method=\"post\"/>
<table id=\"rounded-corner\">
<tr>
<th class=\"rounded\">Numero</th>
<th class=\"rounded\">Numero locomotive</th>
<th class=\"rounded\">Date de réforme</th>
<th class=\"rounded\">Lieu</th>
<th class=\"rounded\">Date d'entrée</th>
<th class=\"rounded\">Motif</th>
<th class=\"rounded\">Opération</th>
<th class=\"rounded\">Situation</th>
<th class=\"rounded\">Date prévision</th>
<th class=\"rounded\">Date de sortie</th>
<th class=\"rounded\">Ajouter intervention</th>
<th class=\"rounded\">Modifier</th>
<th class=\"rounded\">Supprimer</th>
</tr>";
while($row = mysql_fetch_array($req)) {
echo "<tr>";
echo "<td name=\"numero\">" . $row['numero'] . "</td>";
echo "<td>" . $row['numeroloco'] . "</td>";
echo "<td>" . $row['datedereforme'] . "</td>";
echo "<td>" . $row['lieu'] . "</td>";
echo "<td>" . $row['datedentree'] . "</td>";
echo "<td>" . $row['motif'] . "</td>";
echo "<td>" . $row['operation'] . "</td>";
echo "<td>" . $row['situation'] . "</td>";
echo "<td>" . $row['dateprevision'] . "</td>";
echo "<td>" . $row['datedesortie'] . "</td>";
print'
<td><a href="intervention.php"><img src="images/add.png"></a></td>
<td><a href="modifier1.php"><img src="images/edit_user.png"></a></td>
<td><a href="supprimer_immo.php"><img src="images/trash.png"></a></td>';
echo "</tr>";
}
echo "</table>";
echo "</form>";
?>
et voila le code de la page des modifications:
<?php
include('connect.inc');
include('fonction.php');
if(isset($_POST['numero'])) // variable existant
{
if(!empty($_POST['numero']))
{
$sql1="select * from immobilisation where numero='".$_POST['numero']."'";
$r1=mysql_query($sql1);
echo "<form method=\"post\"/>
<table id=\"rounded-corner\">
<tr>
<th class=\"rounded\">Numero</th>
<th class=\"rounded\">Numero locomotive</th>
<th class=\"rounded\">Date de réforme</th>
<th class=\"rounded\">Lieu</th>
</tr>";
while($row=mysql_fetch_array($r1))
{
echo "<tr>";
echo "<td>" . $row['numero'] . "</td>";
echo "<td>" . $row['numeroloco'] . "</td>";
echo "<td>" . $row['datedereforme'] . "</td>";
echo "<td>" . $row['lieu'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
if(isset($_POST['numeroloco']) and isset($_POST['datedereforme']) and isset($_POST['lieu']))
{
$sql="update immobilisation set numeroloco='".$_POST['numeroloco']."', datedereforme='".$_POST['datedereforme']."', lieu='".$_POST['lieu']."' where numero= '".$_POST['numero']."'";
if(mysql_query($sql)) echo"bien modifier";
else echo "Erreur :".mysql_error();
}
}
}
?>
2 réponses
-
Bonjour
Quand tu cliques sur ton lien, tu n'utilises pas le formulaire : il faudrait cliquer sur un bouton submit.
Pas de formulaire, donc pas de $_POST dans le fichier cible. Comme ton lien, c'est "modifier1.php" tout court, la variable $_GET est vide aussi.
Toutes les lignes de ton tableau contiennent les mêmes liens : tu ne peux pas savoir quelle ligne a été cliquée.
Il faudrait que tu ajoutes un identifiant (par exemple ?numero=$row['numero'] à chacun de tes liens, pour être capable de retrouver le numéro de la ligne cliquée avec $_GET.-
-
-
-
-
Voila le code de l'historique:
<?php
include('connect.inc');
include('fonction.php');
// on crée la requête SQL
$sql = 'SELECT * FROM pfe.immobilisation';
// on envoie la requête
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
echo "<form method=\"post\"/>
<table id=\"rounded-corner\">
<tr>
<th class=\"rounded\">Numero</th>
<th class=\"rounded\">Numero locomotive</th>
<th class=\"rounded\">Date de réforme</th>
<th class=\"rounded\">Lieu</th>
<th class=\"rounded\">Date d'entrée</th>
<th class=\"rounded\">Motif</th>
<th class=\"rounded\">Opération</th>
<th class=\"rounded\">Situation</th>
<th class=\"rounded\">Date prévision</th>
<th class=\"rounded\">Date de sortie</th>
<th class=\"rounded\">Ajouter intervention</th>
<th class=\"rounded\">Modifier</th>
<th class=\"rounded\">Supprimer</th>
</tr>";
while($row = mysql_fetch_array($req)) {
echo "<tr>";
echo "<td name=\"numero\">" . $row['numero'] . "</td>";
echo "<td name=\"numeroloco\">" . $row['numeroloco'] . "</td>";
echo "<td name=\"datedereforme\">" . $row['datedereforme'] . "</td>";
echo "<td name=\"lieu\">" . $row['lieu'] . "</td>";
echo "<td>" . $row['datedentree'] . "</td>";
echo "<td>" . $row['motif'] . "</td>";
echo "<td>" . $row['operation'] . "</td>";
echo "<td>" . $row['situation'] . "</td>";
echo "<td>" . $row['dateprevision'] . "</td>";
echo "<td>" . $row['datedesortie'] . "</td>";
?>
<td><a href="intervention.php?numero=<?php echo $row['numero'];?>"><img src="images/ajouter.png" alt="" title="" border="0" /></a></td>
<td><a href="modifier1.php?numero=<?php echo $row['numero'];?>"><img src="images/images.png" alt="" title="" border="0" /></a></td>
<td><a href="supprimer_immo2.php?numero=<?php echo $row['numero'];?>"><img src="images/supprimer.png" alt="" title="" border="0" /></a></td>
<?php
echo "</tr>";
}
echo "</table>";
echo "</form>";
?>
et voila le code de la page des modifications:
<?php
include('connect.inc');
include('fonction.php');
if(isset($_POST['numero'])) // variable existant
{
if(!empty($_POST['numero']))
{
$sql1="select * from immobilisation where numero='".$_POST['numero']."'";
$r1=mysql_query($sql1);
echo "
<table id=\"rounded-corner\">
<tr>
<th class=\"rounded\">Numero</th>
<th class=\"rounded\">Numero locomotive</th>
<th class=\"rounded\">Date de réforme</th>
<th class=\"rounded\">Lieu</th>
</tr>";
while($row=mysql_fetch_array($r1))
{
echo "<tr>";
echo "<td>" . $row['numero'] . "</td>";
echo "<td>" . $row['numeroloco'] . "</td>";
echo "<td>" . $row['datedereforme'] . "</td>";
echo "<td>" . $row['lieu'] . "</td>";
echo "</tr>";
}
echo "</table>";
if(isset($_POST['numeroloco']) and isset($_POST['datedereforme']) and isset($_POST['lieu']))
{
$sql="update immobilisation set numeroloco='".$_GET['numeroloco']."', datedereforme='".$_GET['datedereforme']."', lieu='".$_GET['lieu']."' where numero= '".$_GET['numero']."'";
if(mysql_query($sql)) echo"bien modifier";
else echo "Erreur :".mysql_error();
}
}
}
?>
-
-
Salut,
Fais des echo de tes différentes variables, en commençant par $_POST["numero"].