Page 1 :
<div>
<?php
$reponse = $db->query('SELECT * FROM societe;');
?>
<table border=1>
<form method="post" action="ModifSociete.php">
<?php
$increm = 1;
while($donne = $reponse->fetch()){
?>
<input type="hidden" value="<?php echo $donne['NomSoc']; ?>" name="nomSoc<?php echo $increm; ?>"/>
<tr>
<td><?php echo $donne['ID']; ?></td>
<td><?php echo 'Societe '.$donne['NomSoc']; ?></td>
<td><?php echo $donne['Lieu']; ?></td>
<td><?php echo $donne['Mail']; ?></td>
<input type="hidden" value="<?php echo $donne['ID']; ?>" name="getIdSoc<?php echo $increm; ?>"/>
<td><input class="btn" type="submit" value="Modifier"/></td>
</tr>
<?php
$increm++;
}
$reponse->closeCursor();
?>
<input type="hidden" value="<?php echo $increm; ?>" name="nbIncrem"/>
</form>
</table><br/>
</div>
Page 2 :
<form method="post" action="UpdateSociete.php">
<?php
//WHERE ID = "'.$_POST['getIdSoc'.$i.''].'"
$getNomSoc = $db->query('SELECT * FROM societe;');
$thisSociete =array();
$i=0;
while($data = $getNomSoc->fetch()){
$thisSociete[$i]["NomSoc"] = $data['NomSoc'];
$thisSociete[$i]["Lieu"] = $data['Lieu'];
$thisSociete[$i]["Mail"] = $data['Mail'];
$thisSociete[$i]["ID"] = $data['ID'];
$i++;
}
$j=1;
$thisSocieteNom = "";
$thisSocieteLieu = "";
$thisSocieteMail = "";
if($_POST['nomSoc'.$j.''] == $thisSociete[$j-1]["NomSoc"]){
var_dump($_POST['nomSoc'.$j.'']);
var_dump($thisSociete[$j-1]["NomSoc"]);
$thisSocieteNom = $thisSociete[$j-1]["NomSoc"];
$thisSocieteLieu = $thisSociete[$j-1]["Lieu"];
$thisSocieteMail = $thisSociete[$j-1]["Mail"];
?>
<input type="hidden" value="<?php echo $thisSociete[$j-1]["ID"]; ?>" name="getIdSocBis"/>
<?php
}
else{
$j++;
}
?>
<input type="hidden" value="kangourou" name="passwordAdmin" />
<div>
<h4>Modifier la societe <?php //get le nom de la soiete ?> :</h4>
<table>
<tr>
<td><label>Nom : </label></td>
<td><input type="text" name="ajoutNomSoc" value="<?php echo $thisSocieteNom; ?>"></input></td></tr>
<tr>
<td><label>Lieu : </label></td>
<td><input type="text" name="ajoutLieu" value="<?php echo $thisSocieteLieu; ?>"></input></td>
</tr>
<tr>
<td><label>Mail : </label></td>
<td><input type="text" name="ajoutMail" value="<?php echo $thisSocieteMail; ?>"></input></td>
</tr>
</table>
</div>
<input type="submit" value="Enregistrer"/>
My page 2 is used to update the information in the table from the first pages.
My problem is that i dont know how to select the row i want to update. With my code i always update the first but i dont know what i have to change to select the row i want.
What I want : My table has 4 column. The last one is the submit button. When i click on one of them I go on my second pages (where i can see the information od the row in the text input) and i can change the information of my row (the one where i clicked on the submit button).
How can i do that ?
P.S. : I tried to be the clearest i could...
You can use GET params to pass the ID from page 1 to page 2.
Change
<td><input class="btn" type="submit" value="Modifier"/></td>
To
<td><a href="ModifSociete.php?id=<?php echo $donne['ID']; ?>">Modifier</a></td>
In page 2, try to select the item you parse through GET params $_GET['id']
$getNomSoc = $db->query('SELECT * FROM societe WHERE ID = "' . $_GET['id'] . '";');
I don't think here you need to send post request. what you need to do is:
while($donne = $reponse->fetch()){
?>
<input type="hidden" value="<?php echo $donne['NomSoc']; ?>" name="nomSoc<?php echo $increm; ?>"/>
<tr>
<td><?php echo $donne['ID']; ?></td>
<td><?php echo 'Societe '.$donne['NomSoc']; ?></td>
<td><?php echo $donne['Lieu']; ?></td>
<td><?php echo $donne['Mail']; ?></td>
<input type="hidden" value="<?php echo $donne['ID']; ?>" name="getIdSoc<?php echo $increm; ?>"/>
<td><a href="ModifSociete.php?id=<?php echo $donne['ID']; ?>">Modifier</a> </td>
</tr>
on second page you will get unique ID which will help you to select record based on it