SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast jcorbin's Avatar
    Join Date
    Apr 2010
    Location
    Chicago, IL, US
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question database query failed

    I'm getting an error that says "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"

    I'm doing this through the Lynda.com PHP/MySql tutorial. I've compared the code several times, checked the FAQ's, and tried changing various troubleshooting, but I can't figure it out.

    The code is:

    PHP Code:
    function getSubjectById($subject_id) {
        global 
    $connection;
        
    $query "SELECT * ";
        
    $query .= "FROM subjects ";
        
    $query .= "WHERE id=" $subject_id ." ";
        
    $query .= " LIMIT 1";
        
    $resultSet mysql_query($query$connection);
        
    confirmQuery($resultSet);
        
    // if no rows are returned, then it comes back as false.
        
    if ($subject mysql_fetch_array($resultSet)) {
            return 
    $subject;
        } else {
            return 
    NULL;
        }
    }
    function 
    getPagesById($page_id) {
        global 
    $connection;
        
    $query "SELECT * ";
        
    $query .= "FROM pages ";
        
    $query .= "WHERE id=" $page_id ." ";
        
    $query .= " LIMIT 1";
        
    $resultSet mysql_query($query$connection);
        
    confirmQuery($resultSet);
        
    // if no rows are returned, then it comes back as false.
        
    if ($page mysql_fetch_array($resultSet)) {
            return 
    $page;
        }else {
            return 
    NULL;
        }


  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    likely your $subject_id or $page_id was empty
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast jcorbin's Avatar
    Join Date
    Apr 2010
    Location
    Chicago, IL, US
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks r937! The tip made me look at the file that includes that file. I found the obvious error.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •