mike12255 Posted January 19, 2009 Share Posted January 19, 2009 I have the following code: $id=$_GET['id']; $query = "SELECT locked FROM forumtutorial_posts WHERE postid = $id"; $result = mysql_query($query) or die(mysql_error()); $record = mysql_fetch_assoc($result); if ($record['locked'] < 1 ){ if(isset($_POST['submit'])) and when i run it on my server i get the error : 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 '' at line 1 idk i cant see anything wrong, but then again im really tired. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/141403-solved-sql-syntax-error/ Share on other sites More sharing options...
Lodius2000 Posted January 19, 2009 Share Posted January 19, 2009 try putting angle brackets around id {$id} thats always my first troubleshoot with sql syntax errors, is to put those around all variables Quote Link to comment https://forums.phpfreaks.com/topic/141403-solved-sql-syntax-error/#findComment-740197 Share on other sites More sharing options...
mike12255 Posted January 19, 2009 Author Share Posted January 19, 2009 getting the same error still Quote Link to comment https://forums.phpfreaks.com/topic/141403-solved-sql-syntax-error/#findComment-740203 Share on other sites More sharing options...
Philip Posted January 19, 2009 Share Posted January 19, 2009 "SELECT `locked` FROM `forumtutorial_posts` WHERE `postid` = '{$id}'" Quote Link to comment https://forums.phpfreaks.com/topic/141403-solved-sql-syntax-error/#findComment-740207 Share on other sites More sharing options...
mike12255 Posted January 19, 2009 Author Share Posted January 19, 2009 Thanks mate that worked! but before i hit topic solved mabey somone can answer one more question i have. What do the "`" is the following code mean/stand for/do? SELECT `locked` FROM `forumtutorial_posts` WHERE `postid` = '{$id}'" Quote Link to comment https://forums.phpfreaks.com/topic/141403-solved-sql-syntax-error/#findComment-740209 Share on other sites More sharing options...
Philip Posted January 19, 2009 Share Posted January 19, 2009 The backticks (`) are like normal single quotes (') for table and column names - they are for identifiers. locked is a mysql keyword (if i remember correctly), thus breaking your query. See more here: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html Quote Link to comment https://forums.phpfreaks.com/topic/141403-solved-sql-syntax-error/#findComment-740211 Share on other sites More sharing options...
mike12255 Posted January 19, 2009 Author Share Posted January 19, 2009 strange the query worked without those in another php file of mine :S anyway thanks for the help mates. Quote Link to comment https://forums.phpfreaks.com/topic/141403-solved-sql-syntax-error/#findComment-740213 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.