I am beginner with PHP. I faced that problem when I start my first SQL queries:
Database query On Pages failed : 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 ‘[‘id’]}’ at line 1
There is my SELECT command :
$page_set = mysql_query(
"SELECT * FROM pages WHERE subject_id = {[$subject'id']}", $connection
);
I checked all my database tables and everything is correct. This query works :
$page_set = mysql_query("SELECT * FROM pages" ,$connection)
Going forward, construct your query string in a separate variable like this:
Then run the query like this:
If you do that you can see the fully resolved query string with something like this:
You must test the results value from mysql_query() — it is not a black box; it can and will fail for reasons outside of your control. When the failure occurs, you want to recognize it and handle the error conditions.
Siedbar note: the mysql extension is now deprecated by PHP, so you might want to choose PDO or MySQLi for your current / future work.
And if you’re new to PHP, this is a really great book to help you get started:
http://www.sitepoint.com/books/phpmysql5/