In the table allstudentsAnswers19BE I want to check if a number exists in the column studentnr.
Maybe I have:
$studentnr = ‘1925010101’
At the moment I wrote this:
//get the user with his or her studentnr
$stmt = $pdo->prepare('SELECT * FROM allstudentsAnswers19BE WHERE studentnr = :studentnr');
try{
$stmt->execute(['studentnr' => $studentnr]);
//check if the studentnr exists
if($stmt->rowCount() > 0){
// if the student number exists, insert a new row with the name, student number, week number and the answers
I suppose this will work, but seems a bit excessive.
Is there a simpler way just to check if the student number is in the table before I continue, or exit if the number is not in the table?