Session passing value that was not expected [duplicate]

0

Hello, I'm a programmer and I'm doing a system for the school that I studied, but I encountered a big problem.

              School System

    

<h1 id="titulo">Sistema Escolar</h1>

    <div>
        <ul id="menu">
            <a href="inicio2.html"><li>Página inicial</li></a>
            <li>Informativos</li>
            <li>Bio dos Educadores</li>
            <li>Cursos</li>
        </ul>
    </div>

<div id="lateral">

    <img src="imagens/BrasaoDoCearaPeq.png"/>
    <h4>EEEP SALOMÃO ALVES DE MOURA</h4>

    <h2>Ranking das Salas</h2>
    <ol id="ranking">
        <li>Informática</li>
        <li>Redes</li>
        <li>Edificações</li>
        <li>Comércio</li>
        <li>Secretariado</li>
    </ol>

</div>

<div id="corpo">
    <h1>Selecione o curso desejado</h1>

    <div id="primeiroAno">
        <h3>1º Ano</h3>         
        <ul>    
            <a href="cadAluno.html"><li class="informatica" onclick="<?php $_SESSION['selctcurso'] = 'informatica1'; ?>"><img src="imagens/icones/informatica.png"><br/>Informática</li></a>
            <a href="cadAluno.html"><li class="edificacoes" onclick="<?php $_SESSION['selctcurso'] = 'edificacoes1'; ?>"><img src="imagens/icones/edificacoes.png"/><br/>Edificações</li></a>
            <a href="cadAluno.html"><li class="redes" onclick="<?php $_SESSION['selctcurso'] = 'redes1'; ?>"><img src="imagens/icones/redes.png"/><br/>Redes</li></a>
            <a href="cadAluno.html"><li class="logistica" onclick="<?php $_SESSION['selctcurso'] = 'logistica1'; ?>"><img src="imagens/icones/logistica.png"/><br/>Logística</li></a>
        </ul>
    </div>

    <div id="segundoAno">
        <h3>2º Ano</h3>
        <ul>
            <a href="cadAluno.html"><li class="informatica" onclick="<?php $_SESSION['selctcurso'] = 'informatica2'; ?>"><img src="imagens/icones/informatica.png"><br/>Informática</li></a>
            <a href="cadAluno.html"><li class="comercio" onclick="<?php $_SESSION['selctcurso'] = 'comercio2'; ?>"><img src="imagens/icones/comercio.png"/><br/>Comércio</li></a>
            <a href="cadAluno.html"><li class="redes" onclick="<?php $_SESSION['selctcurso'] = 'redes2'; ?>"><img src="imagens/icones/redes.png"/><br/>Redes</li></a>
            <a href="cadAluno.html"><li class="logistica" onclick="<?php $_SESSION['selctcurso'] = 'logistica2'; ?>"><img src="imagens/icones/logistica.png"/><br/>Logística</li>
        </ul></a>
    </div>

    <div id="terceiroAno">
        <h3>3º Ano</h3>
        <ul>
            <a href="cadAluno.html"><li class="edificacoes" onclick="<?php $_SESSION['selctcurso'] = 'edificações3'; ?>"><img src="imagens/icones/edificacoes.png"><br/>Edificações</li></a>
            <a href="cadAluno.html"><li class="comercio" onclick="<?php $_SESSION['selctcurso'] = 'comercio3'; ?>"><img src="imagens/icones/comercio.png"/><br/>Comércio</li></a>
            <a href="cadAluno.html"><li class="redes" onclick="<?php $_SESSION['selctcurso'] = 'redes3'; ?>"><img src="imagens/icones/redes.png"/><br/>Redes</li></a>
            <a href="cadAluno.html"><li class="secretariado" onclick="<?php $_SESSION['selctcurso'] = 'secretariado3'; ?>"><img src="imagens/icones/secretariado.png"/><br/>Secretariado</li></a>
        </ul>
    </div>

</div>

This is the file code of the file. The problem is when the teacher is going to register a student, he has to go through this screen to select the course when he / she registers. The course is saved in the database as a secretariat. the last course, but it is not to happen, he has to click on a course and the course he clicked is to be saved together with the student. Any more experienced php programmer could help me ?? Thanks in advance for your help.

    
asked by anonymous 25.09.2017 / 01:26

1 answer

2

The code does not make sense since the #.

When you do:

<li class="secretariado" onclick="<?php $_SESSION['selctcurso'] = 'secretariado3'; ?>">

It's the same thing to do:

QualquerCoisa<?php $_SESSION['selctcurso'] = 'secretariado3'; ?>TalvezOutraCoisa

PHP will not understand anything about HTML, it does not even know it exists. The onclick= is the same as the .addEventListener("click", ...) JavaScript, this will only be executed on the client, however PHP ( $_SESSION['selctcurso'] ) is executed before on your server.

It is more than logical that in normal situations, if you are setting N * $_SESSION['selctcurso'] , only the latter is what will hold.

If you want a session value to be set, you can simply make a new request. On this page you are asked to define the session.

    
25.09.2017 / 07:29