I am trying to use a menu link (index.php?) for my pages, so that when the link is selected the information from a database is added to the page. However, I get the following error message:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’` WHERE id = .id’ at line 1 in C:\xampp\htdocs\testsite\index.php:24 Stack trace: #0 C:\xampp\htdocs\testsite\index.php(24): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\testsite\index.php on line 24
$pdo_statement = $conn->prepare("SELECT * FROM pages WHERE id=:id")
You’ve missed a ; from the end of this line. PHP has tried to parse your code and seen the start of the next line before it expected to see it; hence “unexpected”.
“undefined index” means the key you’re trying to get from an array doesn’t exist. If line 23 is the same as before, the array yuo’re looking in is $_GET and the key is "id".
$_GET is a keyed array of the parameters passed in the URL; I’d expect it to look something like www.mywebsite.com/page.php?id=123. If you’re getting this error, you’re not passing an ID. You need to decide how your code will behave if there’s no id passed, then you’ll use isset to make that happen.
The other two errors are from another part of your code, as shown by the line number.