Bonsoir, je dois stocker une information dans une variable cachée en PHP, j'ai essayé de faire quelque
chose mais ça ne fonctionne pas le total reste toujours a 0, si quelqu'un pourrait m'aider s'il vous plait.

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
<!DOCTYPE html>
<html>
<head>
 <title> Commande</title>
</head>
<body>
<form method="get" >
<p>
<label > Votre commande </label> : <input type="text"name="nomarticle"/>
</p>
 
 
<?php
$article = array('pantalon'=>20,'jupe'=>34,'robe'=>45,'veste'=>50); 
 
 
if(!isset($_GET['hidden1'])) {
# if first time submitting, set TOTAL to 0
$TOTAL=0;
} else {
# if form was already submitted, let TOTAL be the sum of the items from the foreach loop
$TOTAL = $_GET['hidden1'];
}
 
foreach($article as $nom => $value){
    if (isset($_GET['nomarticle']) && $_GET['nomarticle']==$nom){
        echo "foreachloop<br>";
 
        # calculate TOTAL sum before printing the hidden field
        $TOTAL = $TOTAL + $value ;
 
         }
}
# add the proper quotes to the hidden fields
echo"<input type=\"hidden\" name=\"hidden1\" value=\"$TOTAL\">";
echo "total: $TOTAL";
?>
<!-- move </form></body> AFTER hidden field is printed.  You were printing/echoing the hidden field outside the closing form tag -->        
</form>
</body>        
</html>