As I have mentioned you need to check if the $_GET['id']
isset and is not empty in the comments, and also when u using prepare()
you must not inject a variable direct into your query you must use placeholder, then bind and execute. PDO have two types of placeholders which are :PlaceHolderName
and ?
<?php
function selected_students($connect)
{
if (isset($_GET['id']) && !empty($_GET['id'])) {
$id = intval($_GET['id']);
$sentence = $connect->prepare("SELECT students.student_name,students.student_id,students.student_thumbnail,courses_students.student_id,courses.course_id from students,courses join courses_students on students.student_id = courses_students.student_id and courses.course_id = ? GROUP BY courses_students.student_id");
$sentence->execute([$id]);
$results = $sentence->fetchall();
if ($results > 0) {
// Results exists display them
}
} else {
// return error the id is not set
}
}
?>
Here are the good places where u can learn pdo
https://phpdelusions.net/pdo
http://jayblanchard.net/demystifying_php_pdo.html