Hello, I've been working on rather simple comment system and when I try and grab all the comments that are "connected" to a post, I receive the Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] error.
The full error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5, 5' at line 1' in C:\xampp\htdocs\post\index.php:90 Stack trace: #0 C:\xampp\htdocs\post\index.php(90): PDO->query('SELECT * FROM c...') #1 {main} thrown inC:\xampp\htdocs\post\index.php on line 90
My code:
$start = 0;
$limit = 10;
if(isset($_GET['p'])) {
$id = $_GET['p'];
} else {
redirect("/");
}
$start = ($id - 1) * $limit;
$query = $database->query("SELECT * FROM comments WHERE post_id = '$id' ORDER BY date DESC LIMIT $start, $limit");
while($row = $query->fetch()) {
$author = $row['author'];
echo $author;
}
I honestly don't understand why this isn't working. I've used the exact same syntax for my post section on my website.
If anything else is needed, just let me know.
Thanks for the help!