Forum Moderators: coopster

Message Too Old, No Replies

Update Records Problems

Update all rows of MYSQL with the same inputs

         

jldr

12:48 pm on Sep 16, 2006 (gmt 0)

10+ Year Member



I have got a problem with my query as it updates in my database all my records starting with the name of SOCIETE (Corporation in French) Let us assume I have two records with the following inputs

FORD (SOCIETE) ROGER (NOM)
FORD (SOCIETE) LOUIS (NOM)

When doing the update it will update the two rows of the MYSQL data base with the same information and return
FORD ROGER

I do not understand how to change my PHP code. Maybe I should list the corporation name (SOCIETE) and name (NOM) before updating in order to differentiate the two but do not know how to do it with a PHP function. Your help would be quite appreciated. Here is the code for the two pages involved :

majmainframe.php :

lister2(mainframe,SOCIETE,lsociete,10);
$requete="select SOCIETE,ADR1,ADR2,VILLE,CP,CIVILITE,NOM,PRENOM,FONCTION,TEL,FAX,EMAIL,DATE,COMMENTAIRES,CC from mainframe where SOCIETE='$lsociete' order by SOCIETE";
$resultat=mysql_query($requete) or die("requete echouee:<br>".mysql_error());
$result=mysql_fetch_row($resultat);

<tr>
<td width="100%" align="center" colspan="4"><b>SOCIETE</b></td>
</tr>
<tr>
<td width="100%" colspan="4"><center><input name="societe" size="120" value="<?php echo "$societe$result[0]";?>" onFocus="this.select()"></center></td>
</tr>
<tr>
<td width="40%" align="center"><b>ADR1</b></td>
<td width="40%" align="center"><b>ADR2</b></td>
<td width="15%" align="center"><b>VILLE</b></td>
<td width="5%" align="center"><b>CP</b></td>

</tr>
<tr>
<td width="40%"><center><input name="adr1" size="40" value="<?php echo "$adr1$result[1]";?>" onFocus="this.select()"></center></td>
<td width="40%"><center><input name="adr2" size="40" value="<?php echo "$adr2$result[2]";?>" onFocus="this.select()"></center></td>
<td width="15%"><center><input name="ville" size="40" value="<?php echo "$ville$result[3]";?>" onFocus="this.select()"></center></td>
<td width="5%"><center><input name="cp" size="10" value="<?php echo "$cp$result[4]";?>" onFocus="this.select()"></center></td>
</tr>
<tr>
<td width="2%" align="center"><b>CIVILITE</b></td>
<td width="29%" align="center"><b>NOM</b></td>
<td width="20%" align="center"><b>PRENOM</b></td>
<td width="49%" align="center" colspan="2"><b>FONCTION</b></td>
</tr>
<tr>
<td width="2%"><center><input name="civilite" size="5" value="<?php echo "$civilite$result[5]";?>" onFocus="this.select()"></center></td>
<td width="29%"><center><input name="nom" size="40" value="<?php echo "$nom$result[6]";?>" onFocus="this.select()"></center></td>
<td width="20%"><center><input name="prenom" size="40" value="<?php echo "$prenom$result[7]";?>" onFocus="this.select()"></center></td>
<td width="49%"><center><input name="fonction" size="50" value="<?php echo "$fonction$result[8]";?>" onFocus="this.select()"></center></td>
</tr>

and the cli_mainframe.php
if ($bouton=="CREER")
{
// insertion du nouvel enreg
echo "$last_code_cli[0]";
$requete="INSERT INTO
mainframe(SOCIETE,CIVILITE,NOM,PRENOM,FONCTION,TEL,EMAIL,FAX,ADR1,ADR2,CP,VILLE,DATE,LOGIN,COMMENTAIRES,CC)
VALUES('$societe','$civilite','$nom','$prenom','$fonction','$tel','$email','$fax','$adr1','$adr2','$cp','$ville','$date','$login','$commentaires','$cc')";

$verif = mysql_query($requete,$id_connex);

if ($verif)
{echo "client $nom créé";}

else {echo "Insertion impossible erreur N° ",
mysql_errno(),mysql_error();}

}
else
{
// mise à jour de la table clients

$requete="UPDATE mainframe SET SOCIETE='$societe',CIVILITE='$civilite', NOM='$nom', PRENOM='$prenom', FONCTION='$fonction', TEL='$tel',
EMAIL='$email', FAX='$fax', ADR1='$adr1', ADR2='$adr2', CP='$cp', VILLE='$ville', DATE='$date', LOGIN='$login', COMMENTAIRES='$commentaires', CC='$cc'
where SOCIETE='$ste'";
$verif = mysql_query($requete,$id_connex);

if ($verif)
{echo "client $societe mis à jour";}
else {echo "Insertion impossible erreur N° ",
mysql_errno(),mysql_error();}
}

henry0

6:46 pm on Sep 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bonjour jldr et bienvenue a WebmasterWorld!
jldr welcome on WebmasterWorld!

As is and at a quick glance I do not see any qualifier
like an ID

We need to see how you built the table

then you need in your query to include something such as:
<<<
$requete="UPDATE mainframe SET SOCIETE='$societe',CIVILITE='$civilite', NOM='$nom', PRENOM='$prenom', FONCTION='$fonction', TEL='$tel',
EMAIL='$email', FAX='$fax', ADR1='$adr1', ADR2='$adr2', CP='$cp', VILLE='$ville', DATE='$date', LOGIN='$login', COMMENTAIRES='$commentaires', CC='$cc'

where SOCIETE='$ste' and id='$id' ";

$verif = mysql_query($requete,$id_connex);
>>>
So create a query that will trigger an update limited to a specific row and delimited for example by a specific ID
This implies that your table has a col for ID that is "auto_incremented".