Bonjour a toutes et tous,

Voici ma question,

J'ai une formule de type "if" dans le bas de ma page php qui me donne un résultat, et je voudrai que ce resultat s'enregistre dans ma base de donnée.

j'ai essayer plusieurs fois avec la fonction inser to mais cela me donne des erreur.

Faut il alors mettre cette fonction dans ma page d'insertion de formulaire ??

Comment faut il faire ??


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
 
 
// Connexion à la base de donnée
mysql_connect("localhost", "xxxx", "xxxxxx");
mysql_select_db('xxxx');
 
 
// Le nom de notre table
$tablename = 'personnes';
 
 
// Tri sur colonne
$tri_autorises = array('date', 'client','ndecde','montant','pose','sm','fournisseur','allegro','livprevue','livconfirmee','statut');
$order_by = in_array($_GET['order'],$tri_autorises) ? $_GET['order'] : 'date'; 'client';'ndecde';'montant';'pose';'sm';'fournisseur';'allegro';'livprevue';'livconfirmee';'statut';
 
 
// Sens du tri
$order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC';
 
 
// Préparation de la requête
$sql = "
        SELECT *
        FROM {$tablename}
        ORDER BY {$order_by} {$order_dir}
";
$result = mysql_query($sql);
 
 
// Notre fonction qui affiche les liens
function sort_link($text, $order=false)
{
        global $order_by, $order_dir;
 
        if(!$order)
                $order = $text;
 
        $link = '<a href="?order=' . $order;
        if($order_by==$order && $order_dir=='ASC')
                $link .= '&inverse=true';
        $link .= '"';
        if($order_by==$order && $order_dir=='ASC')
                $link .= ' class="order_asc"';
        elseif($order_by==$order && $order_dir=='DESC')
                $link .= ' class="order_desc"';
        $link .= '>' . $text . '</a>';
 
        return $link;
}
 
 
// Affichage
?>
<style type="text/css">
a.order_asc,
a.order_desc:hover { 
        padding-right:15px;
        background:transparent url(s_asc.png) right no-repeat;
}
a.order_desc,
a.order_asc:hover {
        padding-right:15px;
        background:transparent url(s_desc.png) right no-repeat;
}
</style>
 
<table width="100%" border="1">
 
        <tr>
 
        <th><?php echo sort_link('DATE', 'date') ?></th>
        <th><?php echo sort_link('CLIENT', 'client') ?></th>
        <th><?php echo sort_link('N° DE CDE', 'ndecde') ?></th>
        <th><?php echo sort_link('MONTANT', 'montant') ?></th>
        <th><?php echo sort_link('POSE', 'pose') ?></th>
        <th><?php echo sort_link('S/M', 'sm') ?></th>
        <th><?php echo sort_link('FOURNISSEUR', 'fournisseur') ?></th>
        <th><?php echo sort_link('ALLEGRO', 'allegro') ?></th>
        <th><?php echo sort_link('LIVRAISON PREVUE', 'livprevue') ?></th>
        <th><?php echo sort_link('LIVRAISON CONFIRMEE', 'livconfirmee') ?></th>
        <th><?php echo sort_link('COMMENTAIRES', 'commentaires') ?></th>
        <th><?php echo sort_link('STATUT', 'statut') ?></th>
        <th><?php echo sort_link('ETAT', '-') ?></th>
 
 
</th> 
        </tr>
 
 
 
<?php while( $row=mysql_fetch_assoc($result) ) : ?>
 
 
<tr>
 
<?php    
switch ($row['statut']){ 
case 'EN COURS': 
$couleur='orange';//a remplacer par le code hexa de la couleur voulue #....... 
break; 
 
case 'LIVRABLE': 
$couleur='green';//a remplacer par le code hexa de la couleur voulue #....... 
break; 
 
case 'SOLDEE': 
$couleur='gray';//a remplacer par le code hexa de la couleur voulue #....... 
break; 
 
case 'RETARD': 
$couleur='red';//a remplacer par le code hexa de la couleur voulue #....... 
break; 
 
default: 
$couleur= 'white';//a remplacer par le code hexa de la couleur par defaut 
break; 
 
} 
echo "<tr style=\"background-color:$couleur;\"> 

<td width=\"100\">"; 
echo $row['date']; 
echo "</td> 

<td width=\"150\">"; 
echo $row['client']; 
echo "</td> 

<td width=\"100\">"; 
echo $row['ndecde']; 
echo "</td> 

<td width=\"100\">"; 
echo $row['montant']; 
echo "</td> 

<td width=\"150\">"; 
echo $row['pose']; 
echo "</td> 

<td width=\"50\">"; 
echo $row['sm']; 
echo "</td> 

<td width=\"250\">"; 
echo $row['fournisseur']; 
echo "</td> 

<td width=\"100\">"; 
echo $row['allegro']; 
echo "</td> 

<td width=\"100\">"; 
echo $row['livprevue']; 
echo "</td> 

<td width=\"100\">"; 
echo $row['livconfirmee']; 
echo "</td> 

<td width=\"150\">"; 
echo $row['commentaires']; 
echo "</td> 

<td width=\"100\">"; 
echo $row['statut']; 
echo "</td> 

  

<td width=\"200\">"; 
 
// Voici ma formule :   
 
$madate=$row['livprevue'];
$madate1=$row['livconfirmee'];
$madate=explode("-",$madate);
$madate1=explode("-",$madate1);
$madate=mktime(0,0,0,$madate[1],$madate[2],$madate[0]);
$madate1=mktime(0,0,0,$madate1[1],$madate1[2],$madate1[0]);
$dateAujourdhui  = mktime(0, 0, 0, date("m"),   date("d"),   date("Y"));
 
if($madate<$dateAujourdhui&&$row['statut']='SOLDEE'){
    echo "<span style='color:black;'>SOLDEE</span>";
 
}elseif($madate1>$dateAujourdhui){
        echo "<span style='color:green;'>EN PRODUCTION</span>"; 
 
}elseif($madate==$dateAujourdhui&&$row['statut']=='SOLDEE'){
    echo "<span style='color:black;'>SOLDEE</span>";
 
}elseif($madate==$dateAujourdhui&&$row['statut']=='LIVRABLE'){
    echo "<span style='color:white;'>LIVRABLE</span>";
 
}elseif($madate<$dateAujourdhui&&$row['statut']=='LIVRABLE'){
    echo "<span style='color:white;'>LIVRABLE</span>";  
 
}elseif($madate==$dateAujourdhui){
        echo "<span style='color:blue;'>DERNIER JOUR</span>";
 
}elseif($madate<$dateAujourdhui){
        echo "<span style='color:red;'>EN RETARD</span>";
 
}elseif($madate>$dateAujourdhui&&$row['statut']=='LIVRABLE'){
    echo "<span style='color:white;'>LIVRABLE</span>";          
 
}else{
    echo "<span style='color:black;'>EN COURS</span>";
}
 
 
?>               
</tr>
 
<?php endwhile ?>
</table>

Merci