I have created a query that works perfectly in phpMyAdmin, however when I try to call it in a .php file I get the following error.
Undefined variable: mothers_name in C:\wamp\www\Family_Tree\showfamily.php on line 56
My code is:
$select_query = "SELECT a.id, CONCAT( a.surname, ', ', a.first_names ) AS child_name, " .
"CONCAT( b.surname, ', ', b.first_names ) AS mothers_name, " .
"CONCAT( c.surname, ', ', c.first_names ) AS fathers_name " .
"FROM family_members a " .
"INNER JOIN family_members b ON a.mother_id = b.id " .
"INNER JOIN family_members c ON a.father_id = c.id" .
"WHERE a.id = " . $user_id;
Am I getting this error because the tables "a","b" and "c" and the fields "mother_id" and "father_id" doesn't exist until the SQL is called through the mysql_query($select_query) function.
The code before line 56 looks up, returns and displays the results as they should.