Hi,
Just a question of neophyte : could you tell me what's wrong with these codes?
I'm able to delete but not to update nor to add.
Thanks?
formulaire.php :
<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:
<?
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>