I have this function in functions.php and I want to fetch data using this function
function getQuestionByNumber($number){
$sql = "SELECT * FROM question WHERE id = '$number'";
$result = mysqli_query($db, $sql);
$row = mysqli_fetch_assoc($result);
return $row;
}
What I am trying to do is using this function I want to fetch question from question table on the test page Heres my test page code:
<?php
include('includes/conn.php');
include('includes/functions.php');
$number = $_GET['num'];
$ques = getQuestionByNumber($number);
?>
<textarea readonly><?php echo $ques['question']; ?></textarea>
But it is giving error:
Notice: Undefined variable: db in C:\xampp\htdocs\onlineExam\testingques.php on line 9
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\onlineExam\testingques.php on line 9
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\onlineExam\testingques.php on line 10
Can someone please help me I am a beginner and just started building applications