25/09/2008, 20h32
|
#1
|
|
Invité de passage
Inscription : mai 2005 Messages : 16 Détails du profil  Informations forums : Inscription : mai 2005 Messages : 16 Points : 2 Points : 2
|
Formulaire mettant à jour une base de données
Hello,
Quelqu'un parviendrait-il à débugger ce code?
Je parviens à effacer mais ni à mettre à jour ni à ajouter...
Merci,
seb
formulaire.php :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| <html>
<body>
<?
if ($_GET["action"] == "update") {
$hote = "localhost";
$username = "root";
$password = "";
$connexion = mysql_connect($hote,$username,$password);
//echo $connexion;
$nomdelabase = "labase";
mysql_select_db($nomdelabase,$connexion);
$requete = "SELECT * FROM latable WHERE numero = $_GET[num]";
$resultat = mysql_query($requete,$connexion);
$test = mysql_fetch_row($resultat);
list($numero,$nom,$informations,$categorie) = $test;
}
?>
<form name="leformulaire" action="execute.php<?
/*if ($_GET[action] == "update")
{echo "?action=update&num=$_GET[num]"; }
elseif ($_GET[action] == "insert")
{echo "?action=insert";}*/
switch($_GET["action"]) {
case "update":
echo "?action=update&num=$_GET[num]";
break;
case "insert":
echo "?action=insert";
break;
}
?>" method="post">au repos
Nom :<br>
<input name="nom" type=text length=30 value=<?if ($_GET[action] == "update") {echo "'$nom'";}?>><br>
Informations :<br>
<textarea name="informations" cols=35 rows=6 value=<?if ($_GET[action] == "update") {echo $informations;}?>></textarea><br>
Catégorie :<br>
<input type=radio name="categorie" value="news" <?if ($categorie == "news") {echo "CHECKED";}?>>
News<br>
<input type=radio name="categorie" value="infos" <?if ($categorie == "infos") {echo "CHECKED";}?>>
Infos<br>
<input type=radio name="categorie" value="photos" <?if ($categorie == "photos") {echo "CHECKED";}?>>
Photos<br>
<input type=submit value="Vazy Envoie !">
</form>
</body>
</html> |
execute.php:
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <?
echo $_POST["nom"]."<br>";
echo nl2br(stripslashes($_POST["informations"]))."<br>";
echo $_POST["categorie"];
$hote = "localhost";
$username = "root";
$password = "";
$connexion = mysql_connect($hote,$username,$password);
//echo $connexion;
$nomdelabase = "labase";
mysql_select_db($nomdelabase,$connexion);
if($_GET["action"] == "suppr") {
$requetespace = "DELETE FROM latable WHERE numero = $_GET[num]";
mysql_query($requetespace,$connexion);
} elseif ($_GET[action] == "update") {
$requetespace = "UPDATE latable SET numero='$_Get[num], nom='$_POST[nom], informations='$_POST[informations], categorie='$_POST[categorie] WHERE numero='$_GET[num]'";
mysql_query($requetespace,$connexion);}
elseif ($_GET[action] == "insert") {
$requetespace = "INSERT latable SET numero='', nom='$_POST[nom], informations='$_POST[informations], categorie='$_POST[categorie]";
mysql_query($requetespace,$connexion);
}
$requete = "SELECT * FROM latable";
echo $requete;
$resultat = mysql_query($requete,$connexion);
echo $resultat;
?>
<table border="1">
<?
while ($test = mysql_fetch_row($resultat)) {
//print_r($test);
list($numero,$nom,$informations,$categorie) = $test;
echo '<tr><td>';
echo $nom;
echo '</td><td>';
echo "<a href = 'execute.php?num=$numero&action=suppr'><img src = 'images/supprimer.gif'></a>";
echo '</td><td>';
echo "<a href = 'formulaire.php?num=$numero&action=update'><img src = 'images/modifier.gif'></a>";
echo '</td></tr>';
}
?>
<tr><td>
<a href = 'formulaire.php?action=insert'><img src='images/ajouter.gif'></a>
</td></tr>
</table> |
|
|
00
|