Bonjour,
Je suis débutant en php et je bute depuis quelques temps sur une problème.
J'essaie de construire un jeu de page qui me permettrait de modifier et supprimer des enregistrements en base de données.
J'ai donc une page de résultat, une page de modification, une page de modification détail et une page avec la requête. J'arrive à construire les 3 premières étapes, mais je bute sur la dernière. Je ne vois pas les modifications sur ma page de résultats. Quelqu'un peut-il m'aider ? Merci.
Voici mes scripts :
Page résultat :
<?php
//connexion au serveur
$connexion=mysql_connect('localhost','root','root')or die('Erreur de connexion');
$base = mysql_select_db('formation_php',$connexion)or die('erreur de connexion a la base');
?>
<table border=1 width="600" cellpadding="5" cellspacing="5" align="center">
<tr>
<th>Nom</th>
<th>Prenom</th>
<th>Age</th>
<th>Tel</th>
<th>Ville</th>
</tr>
<?php
$resultat = mysql_query('SELECT * FROM personnes');
while($ligne = mysql_fetch_array($resultat))
{
echo "<tr><td>";
echo $ligne['nom'];
echo "</td><td>";
echo $ligne['prenom'];
echo "</td><td>";
echo $ligne['age'];
echo "</td><td>";
echo $ligne['tel'];
echo "</td><td>";
echo $ligne['ville'];
echo "</td></tr>";
}
mysql_close();
?>
</table>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
</body>
</html>
Page modifier :
<?php
//connexion au serveur
$connexion=mysql_connect('localhost','root','root')or die('Erreur de connexion');
$base = mysql_select_db('formation_php',$connexion)or die('erreur de connexion a la base');
$requete="SELECT * FROM personnes ORDER BY nom ASC";
$resultat=mysql_query($requete,$connexion);
?>
<!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=utf-8" />
<title>Document sans titre</title>
<link href="file:///SSD/Applications/MAMP/htdocs/AjaxPhpJquery/php_distant/css/styles.css" rel="stylesheet" media="screen" type="text/css" />
</head>
<body>
<h1>Supprimer un produit</h1>
<?php
while($ligne=mysql_fetch_array($resultat))
{
echo("<a style='padding-left:15px'href='produitModifDetail.php?id=".$ligne['id']."&nom=".$ligne['nom']."'>".$ligne['nom']."</a><br />");
}
?>
</body>
</html>
Page modifier détail :
<?php
//connexion au serveur
$connexion=mysql_connect('localhost','root','root')or die('Erreur de connexion');
$base = mysql_select_db('formation_php',$connexion)or die('erreur de connexion a la base');
$requete="SELECT nom,prenom,age,tel,ville FROM personnes WHERE id=".$_GET['id'];
$resultat=mysql_query($requete,$connexion);
mysql_close();
$ligne=mysql_fetch_array($resultat);
?>
<!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=utf-8" />
<title>Ajouter un produit</title>
</head>
<body>
<h1>Modifier <?php echo($ligne['nom']);?></h1>
<form method="post" action="produitSupprimeGo.php">
<label class="label"><input type"text" name="nom" value="<?php echo($ligne['nom']) ?>" />Nom</label>
<label class="label"><input type"text" name="prenom" value="<?php echo($ligne['prenom']) ?>" />Prenom</label>
<label class="label"><input type"text" name="age" value="<?php echo($ligne['age']) ?>" />Age</label>
<label class="label"><input type"text" name="tel" value="<?php echo($ligne['tel']) ?>" />Tel</label>
<label class="label"><input type"text" name="ville" value="<?php echo($ligne['ville']) ?>" />Ville</label>
<input type="submit" value="Enregistrer" />
</form>
</body>
</html>
Page de traitement :
<?php
//connexion au serveur
$connexion=mysql_connect('localhost','root','root')or die('Erreur de connexion');
$base = mysql_select_db('formation_php',$connexion)or die('erreur de connexion a la base');
$requete="DELETE FROM personnes WHERE id=".$_POST['id'];
mysql_query($requete,$connexion);
mysql_close();
header("location:test_affiche.php");
?>