Bonjour à tous
Je viens ici en vous sollicitant pour m'aider car ça fait quelques jours que je galère pour faire fonctionner un scripte à que j'ai adapté à mon besoin.
j'ai deux fichiers ci dessous index.php et requete.php.
j'ai une base de donnée bdmou, j'utilise easyphp14 VC9.
Ce que je souhaite c'est de pouvoir chercher un user en utiliser le formulaire et de pouvoir le modifier, ajouter, supprimer.
quand je lance mes requêtes SQL sur PHPmyadmin ça fonctionnent très bien.
Je vous remercie par avance pour votre aide.


index.php

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
<html>
<head>
 
<style type="text/css">
<!--
.Style4 {font-size: 12px}
-->
</style>
</head>
 
<body>
<br><br>
<form id="form1" name="form1" method="post" action="reqeute.php">
  <table width="420" border="0">
    <tr>
      <td width="169" bgcolor="#DE2916"><label>
        <input name="rechercher" type="submit" id="rechercher" value="Rechercher" />
      </label></td>
      <td width="369" bgcolor="#DE2916"><label>
        <input name="t_rechercher" type="text" id="t_rechercher" />
        <span class="Style4">      Recherche par nom</span> </label></td>
    </tr>
    <tr>
      <td>Nom</td>
      <td><label>
        <input name="t_nom" type="text" id="t_nom" />
      </label></td>
    </tr>
    <tr>
      <td>Prénom</td>
      <td><label>
        <input name="t_login" type="text" id="t_login" />
      </label></td>
    </tr>
    <tr>
      <td>WorkView</td>
      <td><label>
        <input name="t_wkg" type="text" id="t_wkg" />
      </label></td>
    </tr>
    <tr>
      <td>BE</td>
      <td><input name="t_be" type="text" id="t_be" /></td>
    </tr>
    <tr>
      <td colspan="2"><label>
        <input name="nouveau" type="reset" id="nouveau" value="Nouveau" />
        <input name="ajouter" type="submit" id="ajouter" value="Ajouter" />
        <input name="modidier" type="submit" id="modidier" value="Modifier" />
        <input name="supprimer" type="submit" id="supprimer" value="Supprimer" />
      </label></td>
    </tr>
 
  </table>
  <p> </p>
</form>
<? $cn=mysql_connect("localhost","root","");
mysql_select_db("bdmou",$cn); 
ini_set('mysql.trace_mode', true); 
$req=""SELECT BE_NAME,WKG_NAME,LOGIN, LAST_NAME FROM user WHERE LAST_NAME LIKE '%".$_POST['t_rechercher']."%'";
mysql_query($req);
$res=mysql_query($req,$cn);  
?>
 
<table width="630" align="left" bgcolor="#CCCCCC">
<tr >
 
<td width="152">LAST_NAME</td>
<td width="152">WKG_NAME</td>
<td width="152">LOGIN</td>
<td width="66">BE_NAME</td>
</tr>
 
<?
$var=0;
while($row=mysql_fetch_array($res))
{
 
if ($var==0)
{
?>
<tr bgcolor="#EEEEEE">
<td><? echo $row[0];  ?></td>
<td><? echo $row[1];  ?></td>
<td><? echo $row[2];  ?></td>
<td><? echo $row[3];  ?></td>
</tr>
<?
$var=1; 
 }
else
{
?>
<tr bgcolor="#FFCCCC">
<td><? echo $row[0];  ?></td>
<td><? echo $row[1];  ?></td>
<td><? echo $row[2];  ?></td>
<td><? echo $row[3];  ?></td>
</tr><undefined></undefined>
<?
$var=0; 
 }
 }
?>
</table>
</center>
</body>
</html>
reqeute.php

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
<?
$rech=$_POST['rechercher'];
$nom=$_POST['t_nom'];
$LOGIN=$_POST['t_login'];
$WKG=$_POST['t_wkg'];
$BE=$_POST['t_be'];
$cn=mysql_connect("localhost","root","");
or die ("probleme de connection");
mysql_select_db("bdmou",$cn);
or die("probleme de selection de base de donnée");
ini_set('mysql.trace_mode', true);
 if (isset($_POST['rechercher']))
{
$req="SELECT BE_NAME,WKG_NAME,LOGIN, LAST_NAME FROM user WHERE LAST_NAME LIKE '%".$_POST['rechercher']."%'";
 
mysql_query($req);
$res=mysql_query($req,$cn);
$enrg=mysql_fetch_row($res);
 
 if ($enrg[0] == $rech)
{
 
   echo "<form id='form1' name='form1' method='post' action='requete.php'>
    <table width='420' border='0'>
   <tr>
     <td width='169' bgcolor='#CCFF00'><label>
    <input name='rechercher' type='submit' id='rechercher' value='Rechercher' />
     </label></td>
     <td width='369' bgcolor='#CCFF00'><label>
    <input name='t_rechercher' type='text' id='t_rechercher' value='$enrg[0]' />
     </label>Recherche par nom</td>
   </tr>
   <tr>
     <td>Nom</td>
     <td><label>
    <input name='t_nom' type='text' id='t_nom'  value='$enrg[0]'/>
     </label></td>
   </tr>
   <tr>
     <td>login</td>
     <td><label>
    <input name='t_login' type='text' id='t_login' value='$enrg[1]' />
     </label></td>
   </tr>
   <tr>
     <td>WKG</td>
     <td><label>
    <input name='t_wkg' type='text' id='t_wkg' value='$enrg[2]' />
     </label></td>
   </tr>
   <tr>
     <td>BE</td>
     <td><input name='t_be' type='text' id='t_be' value='$enrg[3]' /></td>
   </tr>
   <tr>
     <td colspan='2'><label>
    <input name='nouveau' type='reset' id='nouveau' value='Nouveau' />
    <input name='ajouter' type='submit' id='ajouter' value='Ajouter' />
    <input name='modifier' type='submit' id='modifier' value='Modidier' />
    <input name='supprimer' type='submit' id='supprimer' value='Supprimer' />
     </label></td>
   </tr>
    </table>
    <p> </p>
  </form>";
}
  else
   {
  echo '<body onLoad="alert(\'Client introuvable...\')">';
  echo '<meta http-equiv="refresh" content="0;URL=index.php">';
  }
} 
 
 else
  {
 
 
 
         if (isset($_POST['ajouter']))
 
           if($nom=='')
          {
         echo '<body onLoad="alert(\'Le nom obligatoire\')">';
                               echo '<meta http-equiv="refresh" content="0;URL=index.php">';
 
          }
          elseif ($prenom=='')
          {
          echo '<body onLoad="alert(\'login obligatoire...\')">';
                               echo '<meta http-equiv="refresh" content="0;URL=index.php">';
          }
          elseif($tel=='')
          {
          echo '<body onLoad="alert(\'Workgroup obligatoire...\')">';
                                   echo '<meta http-equiv="refresh" content="0;URL=index.php">';
          }
 
         else
         {
          $rqt="insert user_basalte values('$nom','$LOGIN','$WKG','$BE')";
 
          mysql_query($rqt);
 
            echo '<body onLoad="alert(\'Ajout effectuée...\')">';
          echo '<meta http-equiv="refresh" content="0;URL=index.php">';
          mysql_close();
               }
       if (isset($_POST['modifier']))
 
                                    if($nom=='' || $LOGIN=='' ||$WKG==''   )
          {
 
          echo '<body onLoad="alert(\'fair une recherch avant la modification ou verifiez les champs obligatoire...\')">';
                                   echo '<meta http-equiv="refresh" content="0;URL=index.php">';
          }
          else
          {
           $rqt="update user_basalte set LAST_NAME='$nom',LOGIN='$LOGIN',WKG_NAME='$WKG',BE_NAME='$BE' where LAST_NAME='$rech'";
        mysql_query($rqt);
          echo '<body onLoad="alert(\'Modification effectuée...\')">';
          echo '<meta http-equiv="refresh" content="0;URL=index.php">';
        mysql_close();
         }
       elseif(isset($_POST['supprimer']))       
         {
 
         $rqt="delete  FROM user_basalte  where LAST_NAME ='$rech'";
 
        mysql_query($rqt);
         echo '<body onLoad="alert(\'Suppression effectuée...\')">';
        echo '<meta http-equiv="refresh" content="0;URL=index.php">';
        mysql_close();
         }
 
 
  }
 
?>
<? $cn=mysql_connect("localhost","root","");
mysql_select_db("sdmsg",$cn); 
ini_set('mysql.trace_mode', true); 
$req="SELECT BE_NAME,WKG_NAME,LOGIN, LAST_NAME FROM user_basalte WHERE LAST_NAME LIKE '%".$_POST['t_rechercher']."%'";
mysql_query($req);
$res=mysql_query($req,$cn);  
?>
<table width="630" align="left" bgcolor="#CCCCCC">
<tr >
 
<td width="152">LAST_NAME</td>
<td width="152">WKG_NAME</td>
<td width="152">LOGIN</td>
<td width="66">BE_NAME</td>
 
</tr>
<?
$var=0;
while($row=mysql_fetch_array($res))
{
 
if ($var==0)
{
?>
<tr bgcolor="#EEEEEE">
<td><? echo $row[0];  ?></td>
<td><? echo $row[1];  ?></td>
<td><? echo $row[2];  ?></td>
<td><? echo $row[3];  ?></td>
</tr>
<?
$var=1; 
 }
else
{
?>
<tr bgcolor="#FFCCCC">
<td><? echo $row[0];  ?></td>
<td><? echo $row[1];  ?></td>
<td><? echo $row[2];  ?></td>
<td><? echo $row[3];  ?></td>
 
</tr>
<?
$var=0; 
 }
 }
?>
</table>