Rinn Posted August 1, 2007 Share Posted August 1, 2007 I am trying to get a dynamic nav working and i am having a bit of trouble with the extraction of the information from the database. the error is : Database query failed, Page Set error 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 <?php include 'includes/header.php'; include 'includes/database.php'; ?> <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php // Subject Extract $subject_set = mysql_query("SELECT * FROM subjects",$connection); if(!$subject_set){ die("Database query failed, Subject Set error"); } while ($subject = mysql_fetch_array($subject_set)) { echo "<li>{$subject["menu_name"]}</li>"; } // Subject end //Page Extract $page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}",$connection); if(!$page_set){ die("Database query failed, Page Set error ". mysql_error()); } echo "<ul class=\"pages\">"; while ($page = mysql_fetch_array($page_set)) { echo "<li>{$page["menu_name"]}</li>"; } // Page End echo "</ul>"; ?> </ul> </td> <td id="page"> <h2>Content Menu</h2> <p>Welcome to Opticalx CMS</p> <ul> <li><a href="content.php">Manage Website Content</a></li> <li><a href="new_user.php">Add Staff User</a></li> <li><a href="logout.php">Logout</a></li> </ul> </td> </tr> </table> <?php require ("includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/62761-cms-help/ Share on other sites More sharing options...
hitman6003 Posted August 1, 2007 Share Posted August 1, 2007 You're using double quotes inside of double quotes... change $page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}",$connection); to $page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject['id']}",$connection); Quote Link to comment https://forums.phpfreaks.com/topic/62761-cms-help/#findComment-312436 Share on other sites More sharing options...
rameshfaj Posted August 1, 2007 Share Posted August 1, 2007 Ur query $page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}",$connection); Do like this: $page_set = mysql_query("SELECT * FROM pages WHERE subject_id ='.$subject[id].' ",$connection); Quote Link to comment https://forums.phpfreaks.com/topic/62761-cms-help/#findComment-312499 Share on other sites More sharing options...
hitman6003 Posted August 1, 2007 Share Posted August 1, 2007 Addressing an array element like above $subject[id] causes an additional operation for the php parser. Without quotes around the key name, php will check to see if there is a constant with that name set, if it finds one, it will return the wrong value...if it doesn't then it will check to see if there is an element in the array with that key. It's not wrong per se, but I wouldn't recommend it. Quote Link to comment https://forums.phpfreaks.com/topic/62761-cms-help/#findComment-312501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.