Shanna Posted April 9, 2012 Share Posted April 9, 2012 Hi, I am running MAMP on my Mac with PHP 5.2.17 and MySQL 5.5.22 dB. I am using the PHP with MySQL Essential Training course to learn PHP and My SQl. Part of one of the steps in Ch. 12 has you execute the query below but when I do I get the following error msg. I have looked and tried various things but cannot get his query to work. Please help !!! Thanks in advance, Shanna Error Msg: Database query failed. You have an error in your SQL syntax; check the maual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1. SQL: function get_subject_by_id($subject_id) { global $connection; $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id=" . $subject_id ." "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); // REMEMBER: // if no rows are returned, fetch_array will return false if ($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; Link to comment https://forums.phpfreaks.com/topic/260629-syntax-error-limit-1/ Share on other sites More sharing options...
Jessica Posted April 9, 2012 Share Posted April 9, 2012 echo the query. My guess is $subject_id is empty. Link to comment https://forums.phpfreaks.com/topic/260629-syntax-error-limit-1/#findComment-1335747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.