UPDATE table mysql à partir de radio buttons

Résolu
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 - 10 janv. 2011 à 08:41
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 - 10 janv. 2011 à 13:18
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>

Choisir l'élément à modifier:

<?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"".$tab['nom']."
";
}
echo"";
echo"</form>";
mysql_close($link);
?>



[index.php Retour]

</html>
A voir également:

7 réponses

cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 19
10 janv. 2011 à 09:33
bonjour

as tu essayé

echo $sql="UPDATE tb1 SET nom='billal' WHERE nom='".$selected_radion."'";

pour voir l'aspect de ta requête et voir comment se présente $selected_radion
je crois que le ' n ' est de trop c'est
$selected_radio et pas $selected_radion
essaye voir ça
$sql = "UPDATE `tbl` SET nom=`billal` WHERE `nom` = '".$selected_radio."'";


a++
3
cs_ludwig59 Messages postés 128 Date d'inscription lundi 21 avril 2008 Statut Membre Dernière intervention 6 mai 2011 2
10 janv. 2011 à 11:58
C'est parce que $_POST['soumettre'] n'existe pas. Vous avez oublié le name dans le input type submit.
3
cs_ludwig59 Messages postés 128 Date d'inscription lundi 21 avril 2008 Statut Membre Dernière intervention 6 mai 2011 2
10 janv. 2011 à 09:28
Bonjour,

Dans la requête vous avez mis $selected_radion au lieu de $selected_radio
0
cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 19
10 janv. 2011 à 09:38
@ludwig59
presque synchro ...
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 9
10 janv. 2011 à 11:13
Merci pour vos réponses cod75 et ludwig

Mon code marche à présent:

<!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>Modify</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

Choisir l'élément à modifier:

<?php
$link=mysql_connect('localhost','root','programming01') or die(mysql_error());
mysql_select_db('trying') or die(mysql_error());

if(isset($_POST['soumettre'])){
if(isset($_POST['tomodify'])){
$selected_radio=$_POST['tomodify'];
echo $selected_radio;
$query="UPDATE tb1 SET nom='Billal' WHERE nom='".$selected_radio."'";
$resultat=mysql_query($query)or die(mysql_query());
}else{
echo"Aucun bouton radion n'a été sélectionné";
}
}
$q="SELECT * FROM tb1";
$r=mysql_query($q,$link);
echo"<form action="".$_SERVER['PHP_SELF'].""method="post">";
while($tab=mysql_fetch_array($r)){
echo"".$tab['nom']."
";
}
echo"";
echo"</form>";

?>


[index.php Retour]

</html>
0
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 9
10 janv. 2011 à 11:56
à propos, je n'arrive pas à récupérer la valeur de mon TEXTAREA:

<?php
echo"<form action="1.php" method ="post">";
echo"<textarea cols="15" rows="2" name="nmt"></textarea>";
echo"";
echo"</form>";
if(isset($_POST['soumettre'])){
$nomtext=$_POST['nmt'];
echo $nomtext;
}
?>
0
begueradj Messages postés 273 Date d'inscription dimanche 4 octobre 2009 Statut Membre Dernière intervention 24 juin 2014 9
10 janv. 2011 à 13:18
Vous avez raison Mr. ludwig59
merci beacuoup
0
Rejoignez-nous