UPDATE

Eléphant du PHP | 168 Messages

01 avr. 2005, 15:03

normalement pour effectuer unupdate depuis une requete sql il suffit par exemple demettre un bouton de type submit et on devrai recupere la mis a jour sur la nouvelle Page ? non ?
dans le ode il suffit de mettre un mysql_query("update col=valeur where col=valeur) directement tel quel ?
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.

LaTeX
Invité n'ayant pas de compte PHPfrance

01 avr. 2005, 15:10

Salut à toi,

Il va falloir etre plus précis si tu veux que quelqu'un d'aide.
Mais à priori, tu devrais regarder un cours sur SQL.

Montre nous ton script, au moins la partie avec ton UPDATE.


@+

Eléphant du PHP | 168 Messages

01 avr. 2005, 15:13

voila le code
<html>
<head>
	<title></title>
</head>
<body>
<br>
<h2 align=center> MODIFIER UNE FICHE </H2>
<form method="post" action="page5_3.php">
<?
$user=$_POST['ligne'];
echo "<h3>Vous voulez modifier la fiche correspondant aux données suivantes : </h3>";

Include("sql.inc");
mysql_connect($nom_hote, $nom_utilisateur,$password);
$base=mysql_select_db("adresse");
             if(!$base)
         {
        echo"connexion impossible";
        }
		
$plus=0;

$table=mysql_query("select * from donnée where id='$user'");
echo"<table border=2 width=100%>";
echo"<tr>";
echo"<td align=center><b>Utilisateur";
echo"<td align=center><b>Machine";
echo"<td align=center><b>Vitesse";
echo"<td align=center><b>Adresse IP";
echo"<td align=center><b>Adresse MAC";
echo"<td align=center><b>Systeme D'exploitation";
echo"<td align=center><b>Localisation";

while ($ligne=mysql_fetch_object($table))
{
$plus=$plus+1;
$option="option['$plus']";
echo"<tr>";
echo"<td>$ligne->user</td>";
echo"<td>$ligne->machine</td>";
echo"<td>$ligne->vitesse Mbits/s</td> ";
echo"<td>$ligne->ip</td>";
echo"<td>$ligne->mac</td>";
echo"<td>$ligne->os</td>";
echo"<td>$ligne->localisation</td>";
}
echo"</tr></table>";

echo"<br>";

echo"<table border=0 align=center valign=top><tr><td width=135 height=27><p>
Utilisateur :</td><td width=126 height27 valign=bottom>";

echo"<p><br><form name=\"form\>";
echo"<select name=\"ligne\" size=\"1\">";
echo"<select name=\"ligne\" size=\"1\">";
$table=mysql_query("select * from donnée where id='$user'");
while($ligne=mysql_fetch_object($table))
{
echo"<option value=\"$ligne->id\"> $ligne->user   </option>";
/*echo"<option value=\"$ligne->id\"> $ligne->machine   </option>";
echo"<option value=\"$ligne->id\"> $ligne->vitesse Mbits/s   </option>";
echo"<option value=\"$ligne->id\"> $ligne->ip   </option>";
echo"<option value=\"$ligne->id\"> $ligne->mac   </option>";
echo"<option value=\"$ligne->id\"> $ligne->os   </option>";
echo"<option value=\"$ligne->id\"> $ligne->localisation  </option>";*/
}
echo"</select>";

echo"</td></tr>";

echo"<tr><td width=135 height=27><p>
Quelle champs ?</td><td width=126 height27 valign=bottom>";

echo"<p><br><form name=\"form2\>";
echo"<select name=\"ligne1\" size=\"1\">";
echo"<select name=\"ligne1\" size=\"1\">";
$table=mysql_query("select * from nom ");
while($ligne1=mysql_fetch_object($table))
{
echo"<option value=\"$ligne1->nom\"> $ligne1->nom   </option>";
/*echo"<option value=\"$ligne->nom\"> $ligne->machine   </option>";
echo"<option value=\"$ligne->nom\"> $ligne->vitesse Mbits/s   </option>";
echo"<option value=\"$ligne->nom\"> $ligne->ip   </option>";
echo"<option value=\"$ligne->nom\"> $ligne->mac   </option>";
echo"<option value=\"$ligne->nom\"> $ligne->os   </option>";
echo"<option value=\"$ligne->nom\"> $ligne->localisation  </option>";*/
}
echo"</select>";
echo"</td>
</tr>";

echo"<tr>
<td width=135>
<p>Nouvelle valeur :</td>
<td width=126>
<p><input type=text name='nouvelle' ></td>
</tr>";
$valeur='nouvelle';
$nom=$_POST['ligne'];
$user='ligne1';
mysql_query("update donnée set $nom=$valeur where id=$user");
echo"<tr>
<td width=135 align=center>
<p><br></b><input type=submit name=modifier value=Modifier></td>
<td width=126 align=center>
<p><br></b><input type=reset name=annuler value=Annuler></td>
</tr>
</table>";

?>
</form></form2><p><br>
<?
//mysql_query("update donnée set $nom=$valeur where id=$user");

$lien1="./page2.php";
$text1="accueil";
$lien2="./page5_1.php";
$text2="precedent";
$lien3="./index.php";
$text3="sortir";

echo"<table width=100%>";
echo"<tr>";
echo"<td width=25% align=left>";
echo"<b><a href=\" $lien2\">$text2</a></b>";

echo"</td>";
echo"<td width=50% align=center>";
echo"<b><a href=\" $lien1\">$text1</a></b>";
echo"</td>";
echo"<td width=25% align=right>";
echo"<b><a href=\" $lien3\">$text3</a></b>";
echo"</td></tr></table>";

?>
voila il doit me manquer un mot ou une ligne mais koi et ou?
merci
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.

LaTeX
Invité n'ayant pas de compte PHPfrance

01 avr. 2005, 15:22

Je suis pas sur de mon coup mais dans ta ligne :
mysql_query("update donnée set $nom=$valeur where id=$user");
tu as mis un "$" devant nom.
Ca ne devrais pas être "nom" plutôt ? (le nom du champ dans ta table "données")

Bon courage

Eléphant du PHP | 168 Messages

01 avr. 2005, 15:25

c'est fait expres le nom de la colonne exact n'est pas connu elle est saisie par l'utilisateur parmi une liste deroulante
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.

LaTeX
Invité n'ayant pas de compte PHPfrance

01 avr. 2005, 15:32

As-tu fais un "echo" de tes variables "$nom" ou "$_POST['ligne']" pour vérifier la correspondance avec ta table ?

Eléphant du PHP | 168 Messages

01 avr. 2005, 15:44

voila mon code complet de mise a jour
page1
<html>
<head>
	<title></title>
</head>
<body>
<br>
<h2 align=center> MODIFIER UNE FICHE </H2>
<BR>
<form method="post" action="page5_2.php">
<?
include("sql.inc");
mysql_connect($nom_hote, $nom_utilisateur,$password);
$base=mysql_select_db("adresse");
if(!$base)
{
echo"impossible d ’ouvrir la base";
}?>
<table border="0" align=center width="330" CELLSPACING="0">
<tr><td width="50%">
<p>Quelle fiche ?</td>
<td width="126">
<?
echo"<form name=\"form\>";
echo"<p><select name=\"ligne\" size=\"1\">";
echo"<p><select name=\"ligne\" size=\"1\">";
$table=mysql_query("SELECT * FROM donnée");
while($ligne=mysql_fetch_object($table))
{
echo"<option value=\"$ligne->id\"> $ligne->user</option>";
}
echo"</select>";
//echo"</form1>";
?>
</td>
</tr>
<!--<tr><td width="135" height="27">
<p>Quelle donnée ?</td><td width="126" height"27>
<?
echo"<form name=\"form2\>";
echo"<p><select name=\"ligne2\" size=\"1\">";
echo"<p><select name=\"ligne2\" size=\"1\">";
$table=mysql_query("SELECT*FROM nom");
while($ligne2=mysql_fetch_object($table))
{
echo"<option value=\"$ligne->id\"> $ligne2->nom  </option>";
}
echo"</select>";
echo"</form2>";
?>
</td>
</tr>-->
<tr>
<td width="135" align=center>
<p><br></b><input type="submit" name="modifier" value="Modifier"></td>
<td width="126" align=center>
<p><br></b><input type="reset" name="annuler" value="Annuler"></td>
</tr>
</table><br>
<?
echo"<br>";
$lien1="./page2.php";
$text1="accueil";
$lien2="./index.php";
$text2="sortir";
echo"<table width=100%>";
echo"<tr>";
echo"<td width=25% align=left></td>";
echo"<td width=50% align=center>";
echo"<b><a href=\" $lien1\">$text1</a> <br /></b>";
echo"</td>";
echo"<td width=25% align=right>";
echo"<b><a href=\" $lien2\">$text2</a> <br /></b>";
echo"</td></tr></table>";
?>
</form>
</body>
</html>
page 2
<html>
<head>
	<title></title>
</head>
<body>
<br>
<h2 align=center> MODIFIER UNE FICHE </H2>
<form method="post" action="page5_3.php">
<?
$user=$_POST['ligne'];
echo "<h3>Vous voulez modifier la fiche correspondant aux données suivantes : </h3>";

Include("sql.inc");
mysql_connect($nom_hote, $nom_utilisateur,$password);
$base=mysql_select_db("adresse");
             if(!$base)
         {
        echo"connexion impossible";
        }
		
$plus=0;

$table=mysql_query("select * from donnée where id='$user'");
echo"<table border=2 width=100%>";
echo"<tr>";
echo"<td align=center><b>Utilisateur";
echo"<td align=center><b>Machine";
echo"<td align=center><b>Vitesse";
echo"<td align=center><b>Adresse IP";
echo"<td align=center><b>Adresse MAC";
echo"<td align=center><b>Systeme D'exploitation";
echo"<td align=center><b>Localisation";

while ($ligne=mysql_fetch_object($table))
{
$plus=$plus+1;
$option="option['$plus']";
echo"<tr>";
echo"<td>$ligne->user</td>";
echo"<td>$ligne->machine</td>";
echo"<td>$ligne->vitesse Mbits/s</td> ";
echo"<td>$ligne->ip</td>";
echo"<td>$ligne->mac</td>";
echo"<td>$ligne->os</td>";
echo"<td>$ligne->localisation</td>";
}
echo"</tr></table>";

echo"<br>";

echo"<table border=0 align=center valign=top><tr><td width=135 height=27><p>
Utilisateur :</td><td width=126 height27 valign=bottom>";

echo"<p><br><form name=\"form\>";
echo"<select name=\"ligne\" size=\"1\">";
echo"<select name=\"ligne\" size=\"1\">";
$table=mysql_query("select * from donnée where id='$user'");
while($ligne=mysql_fetch_object($table))
{
echo"<option value=\"$ligne->id\"> $ligne->user   </option>";
}
echo"</select>";

echo"</td></tr>";

echo"<tr><td width=135 height=27><p>
Quelle champs ?</td><td width=126 height27 valign=bottom>";

echo"<p><br><form name=\"form2\>";
echo"<select name=\"ligne1\" size=\"1\">";
echo"<select name=\"ligne1\" size=\"1\">";
$table=mysql_query("select * from nom ");
while($ligne1=mysql_fetch_object($table))
{
echo"<option value=\"$ligne1->nom\"> $ligne1->nom   </option>";
}
echo"</select>";
echo"</td>
</tr>";

echo"<tr>
<td width=135>
<p>Nouvelle valeur :</td>
<td width=126>
<p><input type=text name='nouvelle' ></td>
</tr>";

echo"<tr>
<td width=135 align=center>
<p><br></b><input type=submit name=modifier value=Modifier></td>
<td width=126 align=center>
<p><br></b><input type=reset name=annuler value=Annuler></td>
</tr>
</table>";

?>
</form></form2><p><br>
<?

$lien1="./page2.php";
$text1="accueil";
$lien2="./page5_1.php";
$text2="precedent";
$lien3="./index.php";
$text3="sortir";

echo"<table width=100%>";
echo"<tr>";
echo"<td width=25% align=left>";
echo"<b><a href=\" $lien2\">$text2</a></b>";

echo"</td>";
echo"<td width=50% align=center>";
echo"<b><a href=\" $lien1\">$text1</a></b>";
echo"</td>";
echo"<td width=25% align=right>";
echo"<b><a href=\" $lien3\">$text3</a></b>";
echo"</td></tr></table>";

?>
page 3
<?
$valeur=$_POST['nouvelle'];
$nom=$_POST['ligne'];
$user=$_POST['ligne1'];

echo "<h3>Modification effectués. Voici la nouvelle fiche : </h3>";

Include("sql.inc");
mysql_connect($nom_hote, $nom_utilisateur,$password);
$base=mysql_select_db("adresse");
             if(!$base)
         {
        echo"connexion impossible";
        }
		
$plus=0;
$table=mysql_query("update donnée set $nom=$valeur where id=$user");
$table=mysql_query("select * from donnée where id='$nom'");
echo"<table border=2 width=100%>";
echo"<tr>";
echo"<td align=center><b>Utilisateur";
echo"<td align=center><b>Machine";
echo"<td align=center><b>Vitesse";
echo"<td align=center><b>Adresse IP";
echo"<td align=center><b>Adresse MAC";
echo"<td align=center><b>Systeme D'exploitation";
echo"<td align=center><b>Localisation";

while ($ligne=mysql_fetch_object($table))
{
$plus=$plus+1;
$option="option['$plus']";
echo"<tr>";
echo"<td>$ligne->user</td>";
echo"<td>$ligne->machine</td>";
echo"<td>$ligne->vitesse Mbits/s</td> ";
echo"<td>$ligne->ip</td>";
echo"<td>$ligne->mac</td>";
echo"<td>$ligne->os</td>";
echo"<td>$ligne->localisation</td>";
}
echo"</tr></table>";
?>
<p><br>
<?
$lien1="./page2.php";
$text1="accueil";
$lien2="./page5_1.php";
$text2="precedent";
$lien3="./index.php";
$text3="sortir";

echo"<table width=100%>";
echo"<tr>";
echo"<td width=25% align=left>";
echo"<b><a href=\" $lien2\">$text2</a></b>";

echo"</td>";
echo"<td width=50% align=center>";
echo"<b><a href=\" $lien1\">$text1</a></b>";
echo"</td>";
echo"<td width=25% align=right>";
echo"<b><a href=\" $lien3\">$text3</a></b>";
echo"</td></tr></table>";

?>
voila je ne sais pas ou mettre ma requete de mise a jour
(simple non? :wink: )
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.

LaTeX
Invité n'ayant pas de compte PHPfrance

01 avr. 2005, 15:54

OK

Donc, tu met effectivement un bouton submit qui pointe vers un fichier "valid.php" et c'est dans ce fichier que tu met ton "UPDATE"

Eléphant du PHP | 168 Messages

01 avr. 2005, 15:57

je ne peut pas me service du submit page 2 pour afficher la MàJ page 3 ?
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.

LaTeX
Invité n'ayant pas de compte PHPfrance

01 avr. 2005, 16:24

Si si bien sur mais il faut rajouter "action="Nomdelapage2.php" et la method (POST ou GET) dans la déclaration de "form2".

Mammouth du PHP | 19672 Messages

01 avr. 2005, 16:43

STOP
D'abord, les éléments <form> ne peuvent pas être imbriqués, donc pas de <form> à l'intérieur d'un autre <form>
Corrige d'abord ce truc et après, reviens nous dire si ça ne fonctionne toujours pas :)
Codez en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse :axe:

Eléphant du PHP | 168 Messages

04 avr. 2005, 08:19

ok
je vais donc essayer avec un seul et unique formulaire et je vous tiens au courant
merci
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.

Eléphant du PHP | 168 Messages

04 avr. 2005, 08:24

En fait je ne vois pas trop comment faire
Puis-je reunr mes 2 formulaires?
si oui, comment?
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.

Eléphant du PHP | 168 Messages

04 avr. 2005, 09:13

apres modification du code en ne mettant qu'un seul formulaire cela marche mise a part un chapms qui ne se met pas encore a jour le champs utilisateur
es ce que kelk'un peut me dire pourquoi?
merci
Tous les hommes aspirent à être heureux, mais personne ne s'entend sur la définition du bonheur.
Celui qui a un ami véritable n'a pas besoin d'un miroir.