PHP SQL database query error message -


is there wrong sql code? got tutorial, it's returning following error message

database query failed: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'limit 1' @ line 1

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 no rows returned, fetch array return false     if ($subject = mysql_fetch_array($result_set)){     return $subject;     } else {     return null;      }     } 

best echo query , see looks like.

probably $subject_id contains no value or invalid value. if $subject_id string, should escape (using mysql_real_escape_string) and put inside quotes in query.

[edit]

you know can put enters in strings too, right?

// more readable $query = "   select *   subjects   id = $subject_id   limit 1"; 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -