hello please i am having this error, and it states line 1
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
the mark up language is below
<?php
//this file is the place to save all the basic functions
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
function get_all_subjects() {
global $connection;
//3. perform database querry
$query = "SELECT * FROM subjects ORDER BY position ASC";
$subject_set = mysql_query($query, $connection);
confirm_query($subject_set);
return $subject_set;
}
function get_pages_for_subject($subject_id) {
global $connection;
$query = "SELECT *
FROM pages WHERE subject_id = {$subject_id} ORDER BY position ASC";
$page_set = mysql_query($query, $connection);
confirm_query($page_set);
return $page_set;
}
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;
}
}
?>
yeah, i’m guessing that $sel_sub doesn’t have a value by the time it hits
$sel_subject = get_subject_by_id($sel_subj);
did you miss something in the materials? i would assume that you wouldn’t want to run the function if $sel_sub is empty as it wouldn’t return anything (or generate an error in your instance) since it has to have an ID to get the subject.