-2
function selectLecturer($lecturer_id) { 
    $sql=mysqli_query($con,"SELECT * FROM lecturer WHERE id='$lecturer_id'");
    $row=mysqli_fetch_array($sql);
    echo $row['name']." ".$row['surname'];

}

selectLecturer(1);

This was working in old PHP version, I upgrade my server to php 7.2.2, this function code is not working, How can i fix it?

David
  • 11
  • 7

1 Answers1

0

"Not working" is something different than "deprecated". Not sure what version you were upgrading from, but using the $con variable inside the function will not work without either passing it to the function or defining it global inside the function.

function selectLecturer($lecturer_id) {
    global $con;

    $sql=mysqli_query($con,"SELECT * FROM lecturer WHERE id='$lecturer_id'");
    $row=mysqli_fetch_array($sql);
    echo $row['name']." ".$row['surname'];
}
Ronald Swets
  • 1,669
  • 10
  • 16