Hi everyone, first time here and I hope you can help me. I'm just starting with php and I have a problem. I get an error back from my browser when I load a page, which worked perfectly before,:
"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 '' at line 1"
When adding this bit of code:
PHP Code:
function get_subject_by_id($subject_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id = {$subject_id}";
//$query .= "LIMIT 1";
$subject_set = mysql_query($query, $connection);
confirm_query($subject_set);
//if no rows are returned, then fetch_array will return false
if ($subject = mysql_fetch_array($subject_set)) {
return $subject;
}else{
return NULL;
}
}
I've been over it and over it but I can't figure out what I'm doing wrong. Any help would be apreciated.
I find it's often useful to include the actual query string in the error output to help identify where the problem is. Therefore you might want to add an (optional?) parameter to your confirm_query() function so that you can pass it the query string, and then have it output that string in the error message.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks