0

I'm new to databases and PHP, I need to create a 3rd normalised database and a website that will allow the user to search for a football team or a location and it will display football team in a hyperlinked list that will take them to a details page that will show information on that team, I'm struggling with my database and my query to retrieve all the data I need onto the PHP page, (using PDO), this is my current database: database

I was wondering if I can get any help with making the database better, I've been tweaking it to get it to work but still no luck, my query is:

//preparing the statement
$statementteam = $handler->prepare("
    SELECT `team`.`team_id`, `team`.*, `stadium`.*, `kit_colours`.*, /*`players`.* */
    FROM `team`
    LEFT JOIN `kit_colours` ON `team`.`kit_id` = `kit_colours`.`kit_id` 
    LEFT JOIN `stadium` ON `team`.`stadium_id` = `stadium`.`stadium_id` 
    /*LEFT JOIN `players` ON `team`.`team_id` = `players`.`_id`*/
    WHERE team_id= {$_GET['team_id']}");

//execute statement
$statementteam->execute();

as you can see I have commented out parts of this query as if i leave it uncommented, I get this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'team_id' in where clause is ambiguous' in G:\xampp\htdocs\CIT2318\Assignment\details.php:99 Stack trace: #0 G:\xampp\htdocs\CIT2318\Assignment\details.php(99): PDOStatement->execute() #1 {main} thrown in G:\xampp\htdocs\CIT2318\Assignment\details.php on line 99

any help would be greatly appreciated

chris85
  • 23,846
  • 7
  • 34
  • 51
Kajn
  • 13
  • 4

1 Answers1

0

There is no need to select both team.team_id and team.* - this is causing two columns both team.team_id to be present, causing the issue you are encountering.

retrospectacus
  • 2,518
  • 1
  • 11
  • 18