Hi all,
If you could help me out with the following, I would very much appreciate it. It's something that shouldn't be too difficult,
but I can't seem to get the question defined enough to find the answer though faqs/google etcetera.
I have a website running, with a database for teachers and students. What I am doing, is making a generated list of students that
belong to a certain group (using mysql). This group is also matched to teachers.
My first 1.php contains the following, and gives the teachers that logs in an overview of the students that belong to the same
group he or she belongs to. So far so good (that works!). But now, at the end of the table, I want to create a link that goes to 2.php.
And in 2.php, that specific student's information should be viewable. I tried this using sessions (but then the sessions gets
overwritten for the last created student), and through $_POST. I feel that the last method should be the way to go, but can't get it to work.
I also want not to use browser send id's (to get the protection right), so I think GET is out of the question, right?
This is the code for 1.php (display of all the students's first name who are matching the group the logged in teacher belongs to):
<?php
$userid2 = $_SESSION['mamalou'];
$id2 = $userid2['mentorgroep'];
$studentenresult = mysql_query("SELECT * FROM studenten WHERE mentorgroep='$id2'");
$_SESSION['mijnstudenten'] = mysql_fetch_array($studentenresult);
$mijnstudenten = $_SESSION['mijnstudenten'];
while ($mijnstudenten = mysql_fetch_array($studentenresult)) {
if ($mijnstudenten["voornaam"] != ""){
echo " " . $mijnstudenten["voornaam"];
} else {
echo " " . "<strong>niet bekend</strong>";
}
?>
// trying through use of $S_SESSION
<?php
$student = $mijnstudenten['id'];
$_SESSION['student'] = $student;
echo " " . "<a href='student.php'>volg deze link</a>";
echo $student;
echo "<br>";
// trying through use of method of POST
$student2 = $mijnstudenten['id'];
$_SESSION['student2'] = $student2;
echo "<form action='2.php' method='POST'>";
echo "<input type='hidden' name='$student2'>";
echo "<input type='submit' id='button' value='klik hier'>";
echo "</form>";
?>
<?php } ?>
And the 2.php should present only the information of the student with has been clicked on the link in 1.php:
<?php
$student2 = $_SESSION['student'];
$id3 = $student2;
$studentenresult2 = mysql_query("SELECT * FROM studenten WHERE id='$id3'");
$_SESSION['mijnstudent'] = mysql_fetch_array($studentenresult2);
$mijnstudent = $_SESSION['mijnstudent'];
if ($mijnstudent["voornaam"] != ""){
echo " " . $mijnstudent["voornaam"];
} else {
echo " " . "<strong>niet bekend</strong>";
}
?>
I also tried 2.php with $POST:
<?php
echo $_POST;
$student3 = $_POST['$student2'];
$id3 = $student3;
$studentenresult2 = mysql_query("SELECT * FROM studenten WHERE id='$id3'");
$_SESSION['mijnstudent'] = mysql_fetch_array($studentenresult2);
$mijnstudent = $_SESSION['mijnstudent'];
if ($mijnstudent["voornaam"] != ""){
echo " " . $mijnstudent["voornaam"];
} else {
echo " " . "<strong>niet bekend</strong>";
}
?>
Could someone point me in the right direction for this? I have the feeling the answer is pretty simple,
but have been breaking my mind over this one far too long....
Thanks in advance,
landobee