brian914 Posted August 6, 2008 Share Posted August 6, 2008 I have the following and it gives me an error. 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); if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } If I comment out the following line, it no longer gives me the error. But it also does not do what it needs to $query .= "WHERE id=" . $subject_id ." "; I am getting this from a tutorial, so it seems like I have everything. What am I missing? Thanks a lot for any help! Link to comment https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/ Share on other sites More sharing options...
papaface Posted August 6, 2008 Share Posted August 6, 2008 use 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); if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } Link to comment https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/#findComment-609734 Share on other sites More sharing options...
xstevey_bx Posted August 6, 2008 Share Posted August 6, 2008 try global $connection; $query = "SELECT * FROM subjects WHERE id='$subject_id' LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } Link to comment https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/#findComment-609735 Share on other sites More sharing options...
kenrbnsn Posted August 6, 2008 Share Posted August 6, 2008 You didn't indicate the error you got, so there is no way we can tell you exactly what is wrong. We can only guess. Ken Link to comment https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/#findComment-609738 Share on other sites More sharing options...
papaface Posted August 6, 2008 Share Posted August 6, 2008 The error was he had an extra " Edit: Ok maybe he didnt, just my eyes hurting lol. Ignore my code. Link to comment https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/#findComment-609741 Share on other sites More sharing options...
brian914 Posted August 6, 2008 Author Share Posted August 6, 2008 I tried the above and it did not work. The error I get is: Database query 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 'LIMIT 1' at line 1 Link to comment https://forums.phpfreaks.com/topic/118455-newbie-syntax-help/#findComment-609744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.