raydeneg Posted November 30, 2007 Share Posted November 30, 2007 Hey everyone and thanks in advance. I just started learning php this week but I do have some experience in other languages, mostly c++ but I have dabbled all over. Anyway I am currently teaching my self php with the assistance of "PHP with MySQL Essential Training" from Lynda.com. So while I assume this code should and does work I must be making an obvious typo some where. I have been trying to debug it for some time but I simply cant come up with a working solution. Here is my error message: "DB query failedYou 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" And the code it is referring to: function get_subject_by_id($subject_id) { global $connection; echo $subject_id . "<br> "; // Method 1 of forming the query $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id =" . $subject_id . " "; /* //Method 2 of forming the query $query = "SELECT * FROM subjects WHERE id = {$subject_id} "; */ $result_set = mysql_query($query, $connection); //print_r (mysql_fetch_array($result_set)); confirm_query($result_set); // REMEMBER: //if no rows are returned fetch array will return false if ($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } The code is pretty simple and is simply supposed to figure out which page is called and be able to return the data base information associated with it. Thanks again if anybody can help me, im pretty lost at this point, not sure where I went wrong Quote Link to comment Share on other sites More sharing options...
marcus Posted November 30, 2007 Share Posted November 30, 2007 just do something $query = "SELECT * FROM `subjects` WHERE `id`='{$subject_id}'"; Quote Link to comment Share on other sites More sharing options...
gtal3x Posted November 30, 2007 Share Posted November 30, 2007 method 2 $query overwrites the 1st $query Quote Link to comment Share on other sites More sharing options...
marcus Posted November 30, 2007 Share Posted November 30, 2007 Method 2 is commented out. Quote Link to comment Share on other sites More sharing options...
raydeneg Posted December 1, 2007 Author Share Posted December 1, 2007 Thanks, it worked and yes method 2 was commented out. I was showing that I knew multiple methods of doing the same thing.. and failing Quote Link to comment 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.