Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Error 1064 - Query works when copy and pasting

    When I wrote the code I was using wamp for development. Everything worked fine there. I uploaded it to my server and it broke. If I copy and paste the query that is created into phpMyAdmin it works. I'm at a loss.

    Here is the code that generates the query:
    PHP Code:
    $query "SELECT * FROM `" $databaseName "`.`changes` ORDER BY `entityID`;"
    Here is the error:
    Code:
    A fatal MySQL error occured.
    Query: SELECT * FROM `styles2_systemscans`.`changes` ORDER BY `entityID`;
    Error: (1064) 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

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    The error being reported is either from some other query that failed or the $databaseName variable has some non-printing character in it.

    What's the actual code assigning the database name to $databaseName and the code from the $query = " ... "; statement you posted through to the code that is outputting that error message?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Database name can not contain a period [.] and this query looks like it does.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    He's [trying to] use the database_name.table_name syntax [I assume.]
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts
    First and only query before the one that generates the error:
    PHP Code:
        $query "SELECT `entityID`, `System` FROM `" $databaseName "`.`scans` ORDER BY `entityID`;";
        
    $result mysql_query($query$link) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " $query "<br />\nError: (" mysql_errno() . ") " mysql_error()); 
    Entire query and $result that is generating the error:
    PHP Code:
        $query "SELECT * FROM `" $databaseName "`.`changes` ORDER BY `entityID`;";
        
    $result mysql_query($query$link) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " $query "<br />\nError: (" mysql_errno() . ") " mysql_error()); 
    And the $databaseName is in an include file (that has never given me issues before):
    PHP Code:
    <?php
      session_start
    ();
      
    $databaseName "styles2_systemscans";

      
    $link mysql_connect("localhost","***","***")
        or die(
    mysql_error());
      
    mysql_select_db($databaseName)
        or die(
    mysql_error());
    ?>
    I obviously starred out the username and password

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    The only way I can replicate this exact error message on a select is by providing a null byte into it. I can see the null byte in my debugger, but I cannot see it in the browser (which makes sense). How you got the null byte I couldn't tell; I did mine by manually adding it in:
    Code:
    $query = "SELECT * FROM `" . $databaseName . chr(0) . "`.`core_class` ORDER BY `clsid`;";
    Which gave me the error:
    Code:
    Error: (1064) 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
    All other situations present either differing errors or a description of the cause.

    Delete the line completely and manually retype it in.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Since you are using $link in the mysql_query() statement, you must use the same $link variable in any mysql_error(...) or mysql_errno(...) statement to insure that the error being reported is for the same connection that the query was executed on.

    The symptom you are having of the query error not matching the displayed query statement, is that of having another database connection and the errors being reported are occurring on that other connection.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Actually that's a good point, and I had thought about that one as well.
    We know for sure that something is wrong on this query call, but without the link it is possible its the incorrect message. Although given the message, I can only see it being a char issue elsewhere regardless of multiple connections (so somewhere down the line and it may not be just this query, a query is broken).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    That the OP resorted to using the database name in the query statement, when there's a select_db statement for that database, also suggests there could be more than one database connection floating around in the script.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #10
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I'm at drill or I would have responded.. I'm in my phone so forgive me. I only reference the database be cause its the way I was taught to do it. It seems more complete for some reason.

    Anyway I've tried retyping the line but I'll try it again when I get home. I'll try retyping them all I suppose.

  • #11
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    I'll try retyping them all I suppose.
    ^^^ Why would you go to the trouble of doing that? You must find out why the error is occurring before you can fix it. The different possibilities that have been mentioned so far are just a few of the things that could cause the symptom.

    The error message is typical of an empty numerical value at the end of a query statement - i.e. where id = $some_variable, and the variable doesn't exist or is empty.

    I suspect you have some authentication code, using it's own database connection, that is where the error message being displayed is coming from. The query you are posting is also failing for some reason (did you add the $link variable to the mysql_error() and mysq_errno() statements?) and is triggering the or die() logic, but the message being displayed is from a previous query that failed on the last database connection that was opened.

    Another possibility is that the query that is failing is later in the code, but is not using the $query variable, and the or die() logic for it is using the $query variable and is displaying this previous query statement.

    Do you have php's error reporting set to E_ALL and display_errors set to ON so that php will report and display all the errors it detects? There are likely some php errors occurring that would help pin down what and where the actual problem is at.

    At this point, posting all your code (less any database connection details), would be the quickest way of getting a solution.
    Last edited by CFMaBiSmAd; 04-28-2013 at 01:04 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    Styles2304 (04-28-2013)

  • #12
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts
    OK I'll get in that. I do actually have the errors turned off but I've checked with them on and its the same error with a bunch of warnings caused by the function that converts XML to array. I'll look some things over when I get home based on what you've suggested and see where I'm at. As a last resort I'll post the code.

  • #13
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ok, I did some checking and I had definitely messed up the error reporting. It was echoing $query but the error was from a different statement that didn't reference $query at all ($queryScans). Now, when I set php error reporting to E_ALL, some errors made some more sense. There are some undefined indexes which are causing the 1064 error. Before I assumed that those were a result of the failed query since the lines reported were after - but that was because the error was reporting the wrong query all together.

    To make a long story short, there seems to be an issue with my XML to Array function. I will mark this thread as resolved and create a new one for the new issue.

    Thank you for all the help, I really appreciate it.


  •  

    Posting Permissions

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