7

In a page, two variables are passed in a URL.

In the second page, these variables are initialized. At submit, new page open. The problem is here, I can't recover the session variables.

The script indicate a error (undefined index).

Thanks for help in advance.

Here the code :

First page :

<?php
$requete_cours="SELECT COURS.SIGLE AS SIGLE, ANNEE FROM COURS, MODULE WHERE           COURS.ID_MODULE = MODULE.ID_MODULE and ID_PERSONNE = $userid";
//$requete_cours;   
$res = mysqli_query($cxn, $requete_cours);
echo (mysqli_error ($cxn));
while($ligne = mysqli_fetch_array($res)){
echo '<a href="professeur_absences.php?classe='.$ligne['ANNEE'].'&amp;cours='.$ligne['SIGLE'].'">';
echo $ligne['ANNEE'].' - '.$ligne['SIGLE'].'</a>';
echo '<br/>';
}   
?>  

Second page :

$_SESSION['classe'] = $_GET['classe'];
$_SESSION['cours'] = $_GET['cours'];

Third page :

if(isset($_REQUEST['afficher'])){
    $semaine = $_REQUEST['semaine'];
    $classe = $_SESSION['classe'];
    $cours = $_SESSION['cours'];
    $_SESSION['semaine'] = $semaine;
    $requete_cours_id = "SELECT ID_COURS FROM COURS WHERE SIGLE = $cours";
    //echo $requete_cours;  
    $res = mysqli_query($cxn, $requete_cours_id);
    echo (mysqli_error ($cxn));
    $coursId = mysqli_fetch_array($res);
fortune
  • 3,361
  • 1
  • 20
  • 30
Sab25
  • 85
  • 1
  • 1
  • 6
  • 4
    have you started your pages with `session_start()` ? can't see this in your sample – Dwza Sep 12 '14 at 07:50
  • 1
    session_start is initialize and there is always the error. – Sab25 Sep 12 '14 at 08:11
  • Occasionally, you may have the cookie path set to the non-existent directory. Check phpinfo, session, session.cookie_path. If other than master value (i.e., '/') - change it to the directory you need or reset to default (i.e., '/'). Check also session.save_path and do the same as above. – bbe Jan 12 '16 at 20:28

1 Answers1

7

You must initialize the session by calling session_start() at the beginning of each script. Make sure this is always the first line, as session_start() sends headers.

Find a few examples on basic usage in the PHP docs.

Kaii
  • 20,122
  • 3
  • 38
  • 60