TechGuy1 Posted July 30, 2010 Share Posted July 30, 2010 I am going along with the Lynda.com PHP/MySQL training trying to create a CMS. I have the EXACT code as the tutorial and I keep getting.. 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 'ORDER BY position ASC' at line 3 Here is the code.. CONTENT.PHP <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php if(isset($_GET['subj'])) { $sel_subj = $_GET['subj']; $sel_page=""; }elseif(isset($_GET['page'])) { $sel_subj=""; $sel_page = $_GET['page']; }else { $sel_page=""; $sel_subj=""; } $sel_subject = get_pages_for_subject($sel_subj); ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php ///SUBJECTS//// //gets subjects using an include function $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { //displays the subjects "menu_name" echo "<li"; if($subject["id"] == $sel_subj){ echo " class=\"selected\""; //makes selected subject bold } echo "><a href=\"content.php?subj=" . urlencode($subject["id"]) ." \">{$subject["menu_name"]}</a></li>"; ////DO SAME WITH PAGES////// //gets pages using an include function $page_set = get_pages_for_subject($subject["id"]); echo "<ul class=\"pages\">"; //grabs pages while ($page = mysql_fetch_array($page_set)) { //displays the pages "menu_name" echo "<li"; if($page["id"] == $sel_page) { echo " class=\"selected\""; //makes selected page bold } echo "><a href=\"content.php?page=" . urlencode($page["id"]) . " \">{$page["menu_name"]}</a></li>"; } echo "</ul>"; } ?> </ul> </td> <td id="page"> <h2><?php echo $sel_subject['menu_name']; ?></h2> <br /> <?php echo $sel_page; ?> </td> </tr> </table> <?php require("includes/footer.php"); ?> FUNCTIONS.PHP (When the last function is called is where it screws up) <?php //store all basic functions //confirm queries function confirm_query($result_set) { if (!$result_set) { die("Database query failed: " . mysql_error()); } } function get_all_subjects() { //Perform database query of subjects, orders and puts query into variable $query = "SELECT * FROM subjects ORDER BY position ASC"; //puts subjects into variable $subject_set = mysql_query($query); //tests the above using an include function confirm_query($subject_set); return $subject_set; } function get_pages_for_subject($subject_id) { //Perform database query of pages, orders and puts query into variable $query = "SELECT * FROM pages WHERE subject_id = {$subject_id} ORDER BY position ASC"; //puts pages into variable $page_set = mysql_query($query); //tests the above using an include function confirm_query($page_set); return $page_set; } function get_subject_by_id($subject_id) { $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id=" .$subject_id ." "; $query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); //if now rows returned, fetch array will return false if ($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } ?> ANY HELP? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/209375-please-help/ Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2010 Share Posted July 30, 2010 Which function call is producing the error, how are you calling it, and have you made sure any parameters passed to the function have proper values? Link to comment https://forums.phpfreaks.com/topic/209375-please-help/#findComment-1093283 Share on other sites More sharing options...
TechGuy1 Posted July 30, 2010 Author Share Posted July 30, 2010 Which function call is producing the error, how are you calling it, and have you made sure any parameters passed to the function have proper values? The error happens after I call $sel_subject = get_pages_for_subject($sel_subj); in content.php but the error is in response to function confirm_query($result_set) { if (!$result_set) { die("Database query failed: " . mysql_error()); } } If that makes sense. I am very new to PHP so forgive any ignorance Link to comment https://forums.phpfreaks.com/topic/209375-please-help/#findComment-1093292 Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2010 Share Posted July 30, 2010 Yeah, that makes sense. Make sure that the URL has the variable specified in it: http://whatever/content.php?sel_subj=some_value and echo the value of $sel_subj before the function is called. I suspect it has no value, causing the query string to be "SELECT * FROM pages WHERE subject_id = ORDER BY position ASC"; Link to comment https://forums.phpfreaks.com/topic/209375-please-help/#findComment-1093315 Share on other sites More sharing options...
TechGuy1 Posted August 2, 2010 Author Share Posted August 2, 2010 ok, Ill check it out, thanks for your help Link to comment https://forums.phpfreaks.com/topic/209375-please-help/#findComment-1094361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.