Problème dans mon code php

Fermé
ennaoumi Messages postés 17 Date d'inscription jeudi 22 mai 2014 Statut Membre Dernière intervention 11 juin 2014 - Modifié par Chris 94 le 10/06/2014 à 02:26
 Utilisateur anonyme - 12 juin 2014 à 10:49
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:
<?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();
}
}
}
?>
A voir également:

2 réponses

Utilisateur anonyme
10 juin 2014 à 09:55
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.
1
ennaoumi Messages postés 17 Date d'inscription jeudi 22 mai 2014 Statut Membre Dernière intervention 11 juin 2014
11 juin 2014 à 02:54
j'ai changé mes liens sous cette forme mais ca marche pas
<td><a href="modifier1.php?numero=<?php echo $row['numero'];?>">Modifier</a></td>
0
1 - Ton lien était à l'intérieur du 'un 'print' donc déjà en php. J'espère aue tu as aussi supprimé ce print et mis une balise de fermeture ?>, sinon ta modification n'a aucun sens.
2 - As-tu modifié modifier1.php pour traiter $_GET['numero'] au lieu de $_POST['numero'] ?
0
ennaoumi Messages postés 17 Date d'inscription jeudi 22 mai 2014 Statut Membre Dernière intervention 11 juin 2014
11 juin 2014 à 18:18
ouii j'ai deja supprimé le print
0
Utilisateur anonyme
11 juin 2014 à 18:51
Peux-tu montrer
1 - ton code sans le print
2 - ton traitement avec $_GET au lieu de $_POST
0
ennaoumi Messages postés 17 Date d'inscription jeudi 22 mai 2014 Statut Membre Dernière intervention 11 juin 2014
11 juin 2014 à 21:09
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();
}
}
}
?>
0
reaverlost Messages postés 150 Date d'inscription jeudi 27 mai 2010 Statut Membre Dernière intervention 14 mai 2018 21
10 juin 2014 à 09:38
Salut,

Fais des echo de tes différentes variables, en commençant par $_POST["numero"].
0
ennaoumi Messages postés 17 Date d'inscription jeudi 22 mai 2014 Statut Membre Dernière intervention 11 juin 2014
11 juin 2014 à 02:56
ou je vais mettre les echo dans la page de l'historique ou dans celle des modifications
0