Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You cannot assign <a href="http://www.w3schools.com/php/php_sessions.asp" rel="nofollow">php sessions</a> once the page is loaded already! Well you could but not just with php itself! let me explain:</p> <ul> <li><p>first request ( the form gets downloaded - no modules displayed )</p></li> <li><p>second request ( new form gets downloaded - based on the courseid which has been submitted you display the right modules )</p></li> <li><p>third request ( based on the moduleid submitted you have to populate php sessions for later use )</p></li> </ul> <p>What you were trying to do is to populate the session vars during the second request... however, there's no way you could ever retrieve the right moduleid by doing so! Only the browser and eventually javascript know what's selected at that specific point in time when the page is living just inside the browser!</p> <p>What you actually did, as i just said, is to write your sessions in the second request. <strong>That means that you wrote your session vars prior to the user's module selection!</strong> And what you put to session was nothing more than the last fetched result row in the loop! That is the reason why you always had the last module in your session, which in your case was <code>Interactive Systems</code>!</p> <h2>Let's find a solution now</h2> <p>Provided your course / module selector works properly, displaying the right modules once the users selects its course, you just have to make your third request!</p> <pre><code>&lt;form name="moduleid" [...] &gt; &lt;option value="[moduleid]&gt; [moduleno] - [modulename] &lt;/option&gt; [...] &lt;/form&gt; </code></pre> <p>Based on a structure like this... i just guess this is what your module form could look like... you have to perform the third request to the server which can be either on the same page, as you did for adding the modules select, or on an another one! <strong>the clue code here is something like the one below</strong>... you don't even have to generate any output ;)</p> <pre><code>if ( isset($_POST['moduleid']) ) { $stmt = $mysqli-&gt;prepare('select moduleno, modulename from module where moduleid = ?'); $stmt-&gt;bind_param('s', $_POST['moduleid'] ); if ( $stmt-&gt;execute() ) { $stmt-&gt;bind_result($moduleno, $modulename); $stmt-&gt;fetch(); $_SESSION['moduleid'] = $_POST['moduleid']; $_SESSION['moduleno'] = $moduleno; $_SESSION['modulename'] = $modulename; } } </code></pre> <p>if your course / module selector does not work properly... reffer to my other answer ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload