Session variables between pages

On the page, two variables are passed in the URL.

On the second page, these variables are initialized. On submit, a new page opens. The problem is here, I cannot restore the session variables.

The script indicates an error (undefined index).

Thanks for the help in advance.

Here's 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);

      

+3


source to share


1 answer


You must initialize your session by calling session_start()

at the beginning of each script. Make sure this is always the first line as it session_start()

sends headers.



Find some examples of basic usage in the PHP docs .

+4


source







All Articles