bONJOUR,
je voudrais modifier les données d'un enregistrement via un bouton submit en cochant une case à cocher (ou pas ds un deuxieme temps...)
Malheureusement cela ne fonctionne pas, rien ne se passe dans la base. Ou plutot quand j'ai un seul enregistrement il ya modification, mais si j'ai plusieurs ca ne marche plus. je pense qu'il ya un probleme au niveau du foreach
attention je suis débutant.Voici le code et merci d'avance!!

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<form name="modif_pc" action="modif_pc.php" method="post">
<table width="800" border="0" align= "center" cellpadding="1" cellspacing="1">
<tr><td> 
<?php
require ("Connect.php");
// on seléctionne la base
$connexion = mysql_pconnect (SERVEUR, NOM, PASSE);
mysql_select_db (BASE,$connexion);
$sql = mysql_query("SELECT * FROM permis WHERE id='$_SESSION[id]' ");	
echo'<tr>
<td width=350 height=20 class=bloc>type permis de conduire</td>
<td width=150 height= 20 class=bloc>date obtention du permis</td>
<td width=0 height= 20></td>
<td width=0 height= 20 class=bloc>modifier</td>
<td width=0 height= 20 class=bloc>supprimer</td>
</tr>';
while($row=mysql_fetch_array($sql))
{
echo '<tr>
<td class=bloc2>'.$row['permis'].'</td>
<td class=bloc2><input type=text name=date_permis size=20 value="'.$row['date_permis'].'"></td>
<td width=20 height=20 class=bloc2><input type=checkbox name=pc[] value="'.$row['permis'].'"></td>
<td width=20 height=20 class=bloc2><input name="modifier" type="submit" value="modifier" style="font-size: xx-small"></td>
<td width=20 height=20 class=bloc2><input name="supprimer" type="submit" value="supprimer" style="font-size: xx-small"></td>	</tr>';
}
 
echo '';
?>
</table> 
 
<?php
if(isset($_POST['modifier']))
{
if ($_POST['pc'] == "") {
echo '<p class=rep_info>cochez la ligne à modifier !</p>';
}
else
{
foreach($_POST['pc'] as $val)
{
$sql="UPDATE permis SET date_permis='$_POST[date_permis]' where permis='$val'";
} 
$req= mysql_query($sql); 
 
echo '<p class=contenu>***données modifiées : <font color=#FF0000> '.$val.'</p>';
} }
?>
fin FORM.