www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP problem in the mysql query

  1. #1
    Join Date
    Nov 2012
    Posts
    1

    PHP problem in the mysql query

    Hi everyone, first time here and I hope you can help me. I'm just starting with php and I have a problem. I get an error back from my browser when I load a page, which worked perfectly before,:

    "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 '' at line 1"

    When adding this bit of code:

    PHP Code:
        function get_subject_by_id($subject_id) {
            global 
    $connection;
            
    $query "SELECT * ";
            
    $query .= "FROM subjects ";
            
    $query .= "WHERE id = {$subject_id}";
            
    //$query .= "LIMIT 1";
            
    $subject_set mysql_query($query$connection);
            
    confirm_query($subject_set);
            
            
    //if no rows are returned, then fetch_array will return false
            
    if ($subject mysql_fetch_array($subject_set)) { 
                return 
    $subject;
            }else{
                return 
    NULL;
            }
        } 
    I've been over it and over it but I can't figure out what I'm doing wrong. Any help would be apreciated.

  2. #2
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    In the function you never verify that there is something contained within $subject_id and if its empty, the query will be wrong.

    Also note the whole mysql_* extension is outdated and due for deprecation, it is recommended you use mysqli_* or PDO
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  3. #3
    Join Date
    Nov 2012
    Posts
    32

    try google

    you will definitly find a solution

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,225
    I find it's often useful to include the actual query string in the error output to help identify where the problem is. Therefore you might want to add an (optional?) parameter to your confirm_query() function so that you can pass it the query string, and then have it output that string in the error message.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles