Results 1 to 4 of 4

Thread: PHP problem in the mysql query

  1. #1
    Join Date
    Nov 2012

    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) {
    $query "SELECT * ";
    $query .= "FROM subjects ";
    $query .= "WHERE id = {$subject_id}";
    //$query .= "LIMIT 1";
    $subject_set mysql_query($query$connection);
    //if no rows are returned, then fetch_array will return false
    if ($subject mysql_fetch_array($subject_set)) { 
    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
    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
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  3. #3
    Join Date
    Nov 2012

    try google

    you will definitly find a solution

  4. #4
    Join Date
    Aug 2004
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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