IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Variable session qui ne fonctionne pas


Sujet :

Langage PHP

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut Variable session qui ne fonctionne pas
    Bonjour,

    J'ai un soucis avec une variable session.
    En fait j'ai un formulaire avec 3 listes déroulantes, en fonction des choix sélectionnées mes résultats s'affichent dans un tableau.
    Dans ce formulaire j'ai une variable que je récupère grâce à la méthode POST ou GET, ça depend d'ou est appelé ma page.
    Quelque soit la méthode de récupération je place la valeur de ma variable dans un objet session.

    Lorsque je sélectionne une valeur dans une première liste déroulante ça fonctionne correctement mon objet session contient bien la bonne valeur mais au deuxième changement mon objet session n'a plus de valeur???

    Mes listes déroulantes appellent une fonction javascript qui permet de réexecuter la page php en cours.

    Voilà j'espère avoir donné toutes les infos...

    Merci d'avance pour votre aide.

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 138
    Points : 123
    Points
    123
    Par défaut
    Salut,

    PHP et JavaScript ne se marient pas très bien, c'est pour cela qu'il existe l'AJAX. Cependant, si tu mettais ton code, ca nous aiderait pour t'éclairer.

    Cordialement,

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    Voici mon code:

    C'est la variable $IDsociete qui pose problème.

    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
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
     
    <script language="Javascript">
    function Check(n){
    	//alert('toto'); 
    	if (document.Form1.val1.value>0 || n==1){
    	document.Form1.mode.value=n;
    	document.Form1.submit();
    	}
    }
     
    function ChangeValue(j){
    document.Form1.id.value=j;
    }
     
    function ChangeName(){
     
    	document.Form2.submit();
    }
     
    function Modify(){
    	document.Form3.submit();
    }
     
    function Cloture(p){
    	document.Form4.idact.value=p;
    	document.Form4.submit();
    }
     
    function VoirPlus(y){
    	window.open("InfoAction.php?id="+y,"window20","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=400,height=350,left=0,top=0");
    }
     
    function OuvrirFen(t){
    	window.open("InfoContact.php?id="+t,"window5","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=350,height=320,left=0,top=0");
    }
     
    function TrashAct(g){
    if (confirm('La suppression est définitive, souhaitez-vous réellement continuer ?')){
    	 document.FormSupp.idn.value=g;
    	 document.FormSupp.submit();
    }
    }
    </script>
     
    <?php
     
    error_reporting(E_ALL ^ E_NOTICE);
     
    include("Connection.php");
     
    session_start() ;
     
    $IDCab=$_SESSION['IDcabinet'];
    $IDuser=$_SESSION['IDuser'];
     
     
    $sqlc="Select IDutilisateur,DS from Utilisateur,Cabinet where Utilisateur.IDcabinet=Cabinet.IDcabinet ";
    $sqlc="$sqlc  and Cabinet.IDcabinet='$IDCab' and IDutilisateur='$IDuser' ;";
    $RSc=mysql_query($sqlc)or die('Erreur SQLc !<br>'.$sql.'<br>'.mysql_error()); 
    $row = mysql_fetch_row($RSc);
     
    if( strpos( $row[1], '5' ) !== false)  {
    		$supp=1;
    	}
    echo "supp: $supp\n";
     
    $IDsociete=$_POST["id"];
    echo "IDSocPost: $IDsociete\n";
     
    $_SESSION['societe'] = $IDsociete;
    $monid= $_SESSION['societe'];
    echo "id session: $monid\n";
     
     
    $ID=$_GET["idSoc"];
    echo "IDSocCreAct: $ID\n";
    $_SESSION['idsociete'] = $ID;
    $monid2= $_SESSION['idsociete'];
    echo "id session: $monid2\n";
     
     
     
    if ($IDsociete=="") {
    	if ($ID!="") {
    		$IDsociete=$ID;
    	}
    }
     
    setcookie("TopID", $IDsociete,(time() + 3600)) ;
    echo $_COOKIE['TopID'];
     
    $val0=$_POST["responsable"];
    $val1=$_POST["priorite"];
    $val2=$_POST["etat"];
     
    if ($val0=='') {
     
    		$val0=-1;
     
    }
    if ($val1=='') {
     
    		$val1=3;
     
    }
    if ($val2=='') {
     
    		$val2=3;
     
    }
     
     
     
     
    ?>
     
    <table border=0 width=515>
    <tr>
    		<td align="left" height=42 width=210  background="index/cadre.gif">
    		&nbsp;&nbsp;
    			<font size=2 color="#FFFFFF"><b>LES ACTIONS</b></font>
    		</td>
    		<td align="left" height=42 width=302  background="index/cadre2.gif">
    		&nbsp;&nbsp;
    			<font size=2 color="#FFFFFF"><b>Société: 
    			<?php
     
    			if($IDsociete==""){
    				$IDsociete=$_COOKIE["TopID"];
     
    				//echo "topid: $IDsociete\n"; 
    			}
     
    			$SQL="Select IDsociete, raisonSociale, telephone,fax from Societe where IDsociete='$IDsociete' and IDcabinet='$IDCab';";
    			//echo $SQL;
    			$reqEnt=mysql_query($SQL);
    			while ($donneesSoc= mysql_fetch_array($reqEnt))
    			{
    				$RaisonSociale=$donneesSoc['raisonSociale'];
    				$tel=$donneesSoc['telephone'];
    				$fax=$donneesSoc['fax'];
     
    			}
    			echo $RaisonSociale;
    			?><br>
     
    			&nbsp;&nbsp;&nbsp;&nbsp;Téléphone: <?php echo $tel; ?>&nbsp;&nbsp; Fax: <?php echo $fax; ?>
    			</b></font>
    		</td>
    </tr></br>
    </table>
    	<table border=0 width=550 bgcolor="#FCFAB9">
    	<tr><td><b>
    	<a href="javascript:Modify();" target="MainLab"><font color="#17366B">[Modifier Société]</font></a>&nbsp;&nbsp;
    	<a href="GereContact.asp" target="MainLab"><font color="#17366B">[Contact]</font></a>&nbsp;&nbsp;
    	<a href="gereNote.asp" target="MainLab"><font color="#17366B">[Note]</font></a>&nbsp;&nbsp;
    	Action&nbsp;&nbsp;
    	<a href="GereMission.asp" target="MainLab"><font color="#17366B">[Mission]</font></a>
    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	<?php 
    	$BackSearch=$_POST["BackSearch"];
     
    	?>
    	<a href="Societe.php?BS=<?php echo $BackSearch;?>" target="MainLab"><font color="#17366B">[Retour]</font></a>
    	</b></font></td>
    	</tr>
    	</table>
    	<br>
    	<form method="post" action="GereSoc.php" name="Form2">
    	<?php 
     
    		$SQLz="Select IDutilisateur,nomUser,prenomUser,initiale from Utilisateur where IDcabinet='$IDCab'";
    		$SQLz="$SQLz and etatUser=1 order by nomUser;";
    		$RSz = mysql_query($SQLz);
    	?>
     
    	 <font size="2" ><b>Responsable</b></font>
    	 <select name="responsable" onchange="javascript:ChangeName();">
    		<option value=-1  <?php if($val0 == '-1') { echo 'selected="selected"'; } ?>>Tous les responsables</option> 
     
    		<?php
    			while($data =  mysql_fetch_array($RSz))
    			{
    				echo '<option value="'.$data[0].'"';
    				//if($data[0]==$IDuser) echo ' selected="selected"';
    				if($val0 == $data[0]) { echo 'selected="selected"'; } echo '>'.$data['prenomUser'] ."&nbsp;&nbsp;" .$data['nomUser'] ."&nbsp;&nbsp;" .$data['initiale'];
    				echo '</option>'."\n";
    			}
    		echo '</select>'."\n";
    		?>
     
    	 &nbsp;&nbsp;-&nbsp;&nbsp;
    	 <font size="2" ><b>Lister les actions</b></font>
    	 <select name="etat" onchange="javascript:ChangeName();">
    		<option value=3 <?php if($val2 == '3') { echo 'selected="selected"'; } ?>>Toutes</option> 
    		<option value=0 <?php if($val2 == '0') { echo 'selected="selected"'; } ?>>en retard</option> 
    		<option value=1 <?php if($val2 == '1') { echo 'selected="selected"'; } ?>>du jour</option> 
    		<option value=2 <?php if($val2 == '2') { echo 'selected="selected"'; } ?>>à venir</option> 
     
    	</select>
    	 &nbsp;&nbsp;-&nbsp;&nbsp;
    	 <font size="2" ><b>Importance</b></font>
    	<select name="priorite" onchange="javascript:ChangeName();">
    		<option value=3  <?php if($val1 == '3') { echo 'selected="selected"'; } ?>>Tout</option> 
    		<option value=0  <?php if($val1 == '0') { echo 'selected="selected"'; } ?>>100</option> 
    		<option value=1  <?php if($val1 == '1') { echo 'selected="selected"'; } ?>>10</option> 
    		<option value=2  <?php if($val1 == '2') { echo 'selected="selected"'; } ?>>1</option> 
     
    	</select>
    	 </form>
    	  <?php 
     
     
    		if ($IDsociete=="") {
    			if ($ID!="") {
    				$IDsociete=$ID;
    			}
    			elseif ($_SESSION['societe']!="")
    			{	
    				$IDsociete=$_SESSION['societe'];
    			}
    			else
    			{
    				$IDsociete=$_SESSION['idsociete'];
    			}
     
    		}
     
    		echo "MonIDSociete: $IDsociete\n";
     
    		$SQLw="Select priorite,IDaction,DateAction,titreAction,contact,responsable,info,heure from Action where";
    		$SQLw="$SQLw typeAction=1 and IDtypeAction='$IDsociete'";
    		echo "resp: $val0\n"; 
    		echo "etat: $val2\n";
    		echo "imp: $val1\n";
    		if ($val0!='0' and $val0!='-1') {
    			$SQLw="$SQLw and responsable='$val0' " ;
    		}
    		elseif($val0=='-1') {}
    		elseif($val0==''){
    			$SQLw="$SQLw and responsable='$IDuser' " ;
    		}
     
     
    		$maDate=date("Y-n-j");
    		if ($val2!='3') {
    			if ($val2=='0') {
    				$SQLw="$SQLw and DateAction<'$maDate' " ;
    			}
    				elseif ($val2=='1') {
    					$SQLw="$SQLw and DateAction='$maDate' " ;
    				}
    				elseif ($val2=='2') {
    					$SQLw="$SQLw  and DateAction > '$maDate' " ;
    				}
    		}
     
     
    		if ($val1=='0') {
    			$SQLw="$SQLw and priorite=100 ";
    		}
    			elseif ($val1=='1') {
    				$SQLw="$SQLw and priorite=10 ";
    			}
    			elseif ($val1=='2') {
    				$SQLw="$SQLw and priorite=1 ";
    			}
     
     
    	  $SQLw="$SQLw  order by dateAction asc,heure asc; ";
    	  echo $SQLw;
    	  $RSw = mysql_query($SQLw);
    	  ?>
     
    	  <form method="post" action="CreerAction2.php?idS=<?php echo $IDsociete;?>" name="Form1">
    		<table border=0 width=620>
    	  	<tr>
    		<td align="center" colspan=7><b>
    			<a href="javascript:Check(1);" target="MainLab"><font color="#17366B">[Créer]</font></a>
    			<a href="javascript:Check(2);" target="MainLab"><font color="#17366B">[Modifier]</font></a>
    		<br><br></b></td></tr>
    	  <tr >
    		<td align="center" bgcolor="#17366B" width=20>&nbsp;</td>
    		<td align="center" bgcolor="#17366B" width=20><font size="" color="#FFFFFF"></font></td>
    		<td align="center" bgcolor="#17366B" width=50><font size="" color="#FFFFFF">Date</font></td>
    		<td align="left" bgcolor="#17366B" width=260><font size="" color="#FFFFFF">Action</font></td>
    		<td align="left" bgcolor="#17366B" width=210><font size="" color="#FFFFFF">Contact</font></td>
    		<td align="center" bgcolor="#17366B" width=20><font size="" color="#FFFFFF">&nbsp;</font></td>
    		<td align="center" bgcolor="#17366B" width=20><font size="" color="#FFFFFF">&nbsp;</font></td>
    		<td align="left" bgcolor="#17366B" width=20><font size="" color="#FFFFFF">&nbsp;</font></td>
    		<?php if ($supp==1) {?>
    			<td align="center" bgcolor="#17366B" width=20>&nbsp;</td>
    			<?php } ?>
    	  </tr>
    	  <?php 
    		$i=0;
    		$j=1;
    		while($data =  mysql_fetch_array($RSw))
    		{
     
    		// Selection du contact
    		$Tprio=$data['priorite'];
    		$ActionD=$data['DateAction'];
     
    		ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $data['DateAction'], $params); // récupère la date au bon format
     
    		$idco=$data['contact'];
    		$resp=$data['responsable'];
    		$SQLa1="Select prenomC,nomc from Contact where IDcontact='$idco';";
    		$RSa1 = mysql_query($SQLa1);
     
    			$cont="";
    			while($data1 =  mysql_fetch_array($RSa1)){
    				$cont=$data1['prenomC'] . $data1['nomC'];
    			}
    		// Selection du responsable
    		$SQLa2="Select initiale from Utilisateur where IDutilisateur='$resp';";
    		$RSa2 = mysql_query($SQLa2);
     
    			$resp="";
    			while($data2 =  mysql_fetch_array($RSa2)){
    				$resp=$data2['initiale'];
    			}
     
    	  ?>
    		<tr bgcolor="#FCFAB9">
    			<td align="center" bgcolor="#FCFAB9">
    			<?php 
     
     
    				$maDate=date("Y-n-j");
    				$maDate2=date("d-m-Y");
     
    				if (strtotime ($maDate2) - strtotime ($params[3]."-".$params[2]."-".$params[1]) < 0){$coulPrio=3;}
    				if (strtotime ($maDate2) - strtotime ($params[3]."-".$params[2]."-".$params[1]) > 0){$coulPrio=1;}
    				if (strtotime ($maDate2) - strtotime ($params[3]."-".$params[2]."-".$params[1]) == 0){$coulPrio=2;}
     
     
     
    			$IDact=$data['IDaction'];
    			echo "i:$i\n";
    			if ($i==0) {
     
    			?>
    			<input type="radio" checked  name="data0" OnMouseDown="javascript:ChangeValue(<?php echo $IDact;?>);"/>
    			<input type="hidden" name="id" value="<?php echo $IDact;?>">
    			<?php  
    			$i=1;
    			echo "i2:$i\n";
    			} 
    			else {
    			?>
    			<input type="radio" name="data0"  OnMouseDown="javascript:ChangeValue(<?php echo $IDact;?>);">
    			<?php } ?>
    			</td>
    			<td align="center" bgcolor="#FCFAB9" valign="top" >
    				<a href="javascript:Cloture(<?php echo $IDact;?>);"><img src="image/cloture<?php echo $coulPrio; ?>.gif" alt="cloturer" border=0 width="<%=imgsize%>" height="<%=imgsize%>"></a>
    			</td>
    			<td align="center" bgcolor="#FCFAB9" valign="top"><font size="2">
     
    			<?php echo $params[3]."-".$params[2]."-".$params[1];  ?>
    			<?php 
    			$TitreAction=$data['titreAction'];
    			$heure= $data['heure'];
     
    			if (!is_null($heure) && ($heure!="aa")) { ?>
    				<br><?php echo $heure;?>
    			<?php } ?>
    			</font></td>
    			<td align="left" bgcolor="#FCFAB9" valign="top"><font size="2"><b><?php echo $TitreAction;?></b></font></td>
    			<td align="left" bgcolor="#FCFAB9" valign="top">
    				<table border=0>
    					<tr>
    						<td>
    						<?php if ($cont!="") {?>
    							<a href="javascript:OuvrirFen(<?php echo $idco; ?>);"><img src="image/cand1.gif" alt="<?php echo $infoC; ?>" border=0 width="<%=imgsize%>" height="<%=imgsize%>"></a>
    						<?php } ?>
    						</td>
    						<td valign="top"><font size="2"><?php echo $cont ?></font></td>
    					</tr>
    				</table>
    			</td>
    			<td align="center" bgcolor="#FCFAB9" valign="top">
    			<?php if ($data['info']!="") {?>
    				<a href="javascript:VoirPlus(<?php echo $IDact;?>);"><img src="image/info.gif" width="<%=imgsize%>" height="<%=imgsize%>" border=0 alt="<%=infos%>"></a>
    			<?php } ?>
    			</td>
    			<td align="center" bgcolor="#FCFAB9" valign="top"><font size="1"><?php echo $data['priorite'];?></font></td>
    			<td align="center" bgcolor="#FCFAB9" valign="top"><font size="1"><?php echo $resp;?></font></td>
    			<?php if ($supp==1) {?>
    				<td align="center" bgcolor="#FCFAB9" valign="top"><?php echo $IDact;?>
    	  			<a href="javascript:TrashAct(<?php echo $IDact;?>);"><img src="image/trash.gif" border=0 alt="Supprimer l'action" height="<%=imgsize%>" width="<%=imgsize%>"></a>
    				</td>
    			<?php } ?>	
    		</tr>
    		<?php 
     
    		}
    		echo "i: $i\n"; 
    		echo "id: $IDact\n"; 
     
    		?>
    	  </table>
    			<input type="hidden" name="val1" value="<?php echo $i;?>">
    			<input type="hidden" name="mode">  
    			<input type="hidden" name="act1" value="<?php echo $val0;?>">
    			<input type="hidden" name="act2" value="<?php echo $val1;?>">
    			<input type="hidden" name="act3" value="<?php echo $val2;?>">
    	  </form>
    	  <form method="post" action="CreerSociete.php" name="Form3">
    	  		<input type="hidden" name="id" value="<?php echo $idsoc;?>">
    			<input type="hidden" name="mode" value=2>  
    	  </form>
    	  <form method="post" action="Cloturer.php" name="Form4">
    			<input type="hidden" name="act1" value="<?php echo $val0;?>">
    			<input type="hidden" name="act2" value="<?php echo $val1;?>">
    			<input type="hidden" name="act3" value="<?php echo $val2;?>">
    	  		<input type="hidden" name="idact">
    	  </form>
    	  <form method="post" action="TraiteAction2.php" name="FormSupp">
    		<input type="hidden" name="idn">
    		<input type="hidden" name="mode" value="3">
    		<input type="hidden" name="ids" value="<?php echo $IDsociete;?>">
    	</form>
    Merci d'avance pour votre aide!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Variable SESSION qui ne fonctionne pas sous IE et FF
    Par tardmonkey dans le forum Langage
    Réponses: 7
    Dernier message: 13/06/2013, 10h07
  2. Variable globale qui ne fonctionne pas
    Par the-morpher dans le forum Windows Forms
    Réponses: 4
    Dernier message: 21/03/2009, 22h01
  3. Réponses: 2
    Dernier message: 06/09/2007, 09h23
  4. Réponses: 5
    Dernier message: 08/08/2007, 12h35
  5. [Sécurité] Session qui ne fonctionne pas!!!!
    Par philippef dans le forum Langage
    Réponses: 5
    Dernier message: 27/10/2005, 17h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo