-1

I have created a Function which will find the assistant coach for a team within the database. (i have checked the query within phpmyadmin and it works).

function assistantCoach() {
   $query_assistcoach = "SELECT * FROM coach, team WHERE team.team_id = '1' and coach.team_id = '1' AND coach.team_role = 'Assistant' ";
   $assistcoach = mysql_query($conn, $query_assistcoach);
}

I would like to output the coaches fname and sname on Team Page the coach is linked with.

I have tried using $assistcoach = assistantCoach(); at the top of the page and then within the page using <?php echo ($assistcoach['fname']) ?>

The above is throwing a

Fatal error: Uncaught Error: Call to undefined function mysql_query() in \inc\functions.php:25 Stack trace: #0 \teampage.php(9): assistantCoach() #1 {main} thrown in \inc\functions.php on line 25

Line 25 is $assistcoach = mysql_query($conn, $query_assistcoach); part of the function.

Milad Bahmanabadi
  • 946
  • 11
  • 27
Andy Terry
  • 53
  • 6

1 Answers1

-1

You should pass $conn parameter to the function:

$assistcoach = assistantCoach($conn);

or connect to the database inside function.

Moreover, the function must return something to use the returned data, so you need to add in the end:

return($assistcoach);
Viktor
  • 62
  • 1
  • 8