Hi,
J'ai besoin de mettre à jour ma base de données à partir de valeurs récupérées de boutons radio.
Pour celà, j'ai simplifié le problème comme suit, or après l'exécution du fichier qui suit, je remarque que la table n'est pas mise à jour !
Toute indication est bienvenue!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Trying </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h2>Choisir l'élément à modifier:</h2></br>
<?php
$link=mysql_connect('localhost','root','programming01') or die(mysql_error());
mysql_select_db('trying') or die(mysql_error());
//$result = mysql_query("UPDATE example SET age='22' WHERE age='21'") or die(mysql_error()
// to get the value of a radio button we must access again the names
if(isset($_POST['tomod'])){
// echo"boutton appuyé";
$selected_radio=$_POST['tomod'];
//echo $selected_radio;
//$r=mysql_query("UPDATE tb1 SET nom='billal'WHERE nom='".$selected_radion."'");
$sql="UPDATE tb1 SET nom='billal' WHERE nom='".$selected_radion."'";
$r=mysql_query($sql);
if($r) echo"Mise à jour réussie !"; else echo"false";
//echo $r;
}
echo"<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
$result=mysql_query("SELECT*FROM tb1")or die (mysql_error());
while($tab=mysql_fetch_assoc($result)){
echo"<input type=\"radio\" name=\"tomod\" value=\"".$tab['nom']."\"/>".$tab['nom']."<br/>";
}
echo"<input type=\"submit\" name=\"modifier\"value=\"modifier\"/>";
echo"</form>";
mysql_close($link);
?>
<br/>
<a href="index.php">Retour</a>
</body>
</html>