Hello.
I have a function which should find students based on their ID. The function is as follows:
[php] function find_student_by_id($id) { //so this function should return an associated array called teacher which has all teacher propertuies associated to that ID
global $db_connection;
$sql = "SELECT * FROM students_table";
//$sql .= "WHERE id='" . db_escape($db_connection, $id) . "' ";
$sql .= "WHERE id='" . $id . "' ";
$result = mysqli_query($db_connection, $sql);
//echo $result;
confirm_result_set($result);
$student = mysqli_fetch_assoc($result); // find first
mysqli_free_result($result);
return $student; // returns an assoc. array called student
}[/php]
As you can see, the function also calls another function inside it, called - confirm_result_set($result):
[php] function confirm_result_set($result_set) {
if (!$result_set) {
exit(“Database query failed jool!.”);
}
}
[/php]
In my exercise I created a form which takes us to the page (welcome.php) where this function above is run. The form successfully connects to the database and adds a new entry into the database (so I know I am connecting to the database ok). After doing so, it directs to this page passing an id string. This gets passed successfully.
The problem appears to be that function function confirm_result_set($result_set) is not returning a result_set as I keep getting the “Database query failed jool!.” error.
I took these functions from a tutorial and I am trying to adapt them. What is confusing me slightly is that the function confirm_result_set passes a variable called ‘result_set’ but the function function find_student_by_id is passing a variable called ‘result’. I tried making these the same but this didn’t seem to make a difference?
So I’m stuck here. Any advice / help would be great.
Many thanks.