#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    322
    Rep Power
    0

    Simple syntax error mysql and i can't find it


    I'm getting the following error message and I cant find the problem
    tetstYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc (id,topicid,topic) VALUES (NULL,'', '')' at line 1


    PHP Code:
    // Create connection
    function doDB() {
        global 
    $mysqli;

        
    //connect to server and select database; you may need it
        
    $mysqli mysqli_connect("localhost""*****""*******""shawnhbk_**********");

        
    //if connection fails, stop script execution
        
    if (mysqli_connect_errno()) {
            
    printf("Connect failed: %s\n"mysqli_connect_error());
            exit();
        }
    }
    //connect to database
        
    doDB();
    $add_master_sql =("INSERT INTO desc (id,topicid,topic)
                           VALUES (NULL,'
    $language', '$safe_title')");
        
    $add_master_res mysqli_query($mysqli$add_master_sql) or die(mysqli_error($mysqli)); 
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,066
    Rep Power
    1990
    That's because 'desc' is a reserved keyword in MySQL. The best thing to do is rename the table to something else like "description" so that it doesn't clash with any of the reserved words like that. If that's not possible you can escape db, table and column names with back-ticks like:

    Code:
    INSERT INTO `desc` (`id`,`topicid`,`topic`)

IMN logo majestic logo threadwatch logo seochat tools logo