I have the PHP below and it works fine. But this form has room for 2 student numbers and I want to check both.
I tried just duplicating the code below, changing the $stmt1 $stmt2, but I just get my $_SESSION[‘error’] message:
$_SESSION[‘error’] = ‘Step 2.2 Check the SN: This student number: ’ . $studentnr2 . ’ is not in the 20BE classes students’ database. Please try again!’;
Also, $studentnr2 is not displayed. I checked and $studentnr2 is passed to PHP and appears in the text file accompanying the file, and in the text message which PHP writes to a text file.
I also tried calling $pdo $pdo1 and $pdo2, but PHP will not accept that. Is $pdo somehow reserved??
I thought I could call it anything!
Like I said, the code below works fine, and PHP continues and uploads the file I want with the message containing both student numbers, names and email.
How can I integrate the second student number in the checking process??
include '../../includes/studentdbWriteto.inc.php';
//check if the studentnr exists in this course names and numbers list
$stmt1 = $pdo->prepare('SELECT 1 FROM allstudents20BE WHERE studentnr = ?');
try{
$stmt1->execute([$studentnr1]);
//echo 'row count is ' . $stmt1->rowCount();
if($stmt1->rowCount() == 0){
//echo 'this student is not in the database';
$_SESSION['error'] = 'Step 2 Check the SN: This student number: ' . $studentnr1 . ' is not in the 20BE classes students\' database. Please try again!';
//echo $_SESSION['error'];
header('Location: /uploadFiles20BE/uploadessays_pairs_V1.html.php');
exit();
// if the student number exists, carry on, save the answers
}
}
catch(PDOException $e){
$_SESSION['error'] = $e->getMessage();
//echo $_SESSION['error'];
header('Location: /uploadFiles20BE/uploadessays_pairs_V1.html.php');
exit();
}
you need to restructure your database table a little bit. There’s no to have two separate tables (that is what it looks like you are doing?) as all you have to do is if the table didn’t successfully update then just insert the new student’s data into the table (after making sure the student doesn’t exist) and off you go. Usually you will have some kind of registration where you don’t have to check if the user exists, so most of the time it’s a mute point. Like I said, look at that link as I think it will help you out tremendously. Well, I kind of take it back with only having one database table, but it should be separated at first, by that the student information in one table and the grades for the test(s) in another table then you can simply join them if you need to.