My program isn't working and I'm unsure which point exactly I've gone wrong
- Basically, I get an artist_id from my first PHP page via get.
- I have 2 other tables. 1 Table contains the information I want. However, I need to compare my initial value, with an external table to establish a relationship from the main table where I need the information from.
- The logic behind my SQL Query is correct. However, I am unsure whether I made a syntax error which I'm not able to figure out.
Also, I find it very tedious trying to debug these programs. What would be the best way to check whether the syntax for my SQL queries are correct or not?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
table,th,td{
border: 1px solid black;
}
</style>
<title>My second PHP page</title>
</head>
<body>
<?php
include 'config.php';
?>
<?php
$pdo = new PDO("mysql:dbname=${config['dbname']};host=${config['host']};charset=utf8",
$config['name'], $config['pass']);
$my_id= $_GET['val'];
$sql = ' SELECT name, venue, schedule FROM events'
.' WHERE event_id IN'
.' (SELECT event_id FROM performs'
.' WHERE artist_id = :variable) '
.' ORDER BY schedule DESC,
event_id ASC';
$stmt->execute([':variable' => $my_id ]);
$result = $pdo->query($sql);
echo "<table>";
echo "<tr><th>Event name</th><th>Venue</th><th>Schedule</th></tr>";
foreach ($result as $row) {
echo "<tr>";
$name = htmlspecialchars($row['name']);
$venue = htmlspecialchars($row['venue']);
$schedule = htmlspecialchars($row['schedule'];
echo "<td>".$name."</td>";
echo"<td>".$venue."</td>";
echo"<td>".$schedule."</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>