Hi Everyone, I am struggling to fix this stupid problem I have with pdo php insert.

I have this working on a different insert, but for some reason, this is just not working.
I keep getting the error

"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 'keys, statement, interests) values (?, ?, ?, ?)' at line 1"

I have checked, checked again, then checked again that each column name is correct, each variable is also correct.

Can someone point out where I am going wrong, or where the problem is within the code.

    if ($stmt = $mysqli->prepare("INSERT INTO S4HCandidate_Cv (uid, keys, statement, interests)  
     values (?, ?, ?, ?)")) {

    // Bind our 4 params
    $stmt->bind_param('isss', $canref, $cancvkeys, $cancvstatement, $cancvinter);

    //form values
        $canref             = "$canref";            //1
        $cancvkeys          = "$cancvkeys";         //2
        $cancvstatement     = "$cancvstatement";    //3     
        $cancvinter         = "$cancvinter";        //6     
    // Execute the prepared Statement
    $stmt->execute();           
    /* Close the statement */   
    $stmt->close(); 
    }

The really strange thing is, if I add a table name that is not in the database I get the same error,

I have also tried -

    $sql = "INSERT INTO S4HCandidate_Cv (uid, keys, statement, interests) VALUES (:cvuid,:cvkeys,:cvstatement,:cvinterests)";
    $q = $conn->prepare($sql);
    $q->execute(array(':cvuid'=>$canref,
                      ':cvkeys'=>$cancvkeys,
                      ':cvstatement'=>$cancvstatement,
                      ':cvinterests'=>$cancvinter));

and

    $stmt = $conn->prepare("INSERT INTO S4HCandidate_Cv (uid, keys, statement, interests) VALUES (?, ?, ?, ?)");
    $stmt -> bindParam(1, $canref);
    $stmt -> bindParam(2, $cancvkeys);
    $stmt -> bindParam(3, $cancvstatement);
    $stmt -> bindParam(4, $cancvinter);

With the above, I dont get any error message, but the database is not updated either.

Updated...

I have also tried

    $stmt = $conn->prepare('INSERT INTO S4HCandidate_Cv (uid, keys, statement, interests) 
    VALUES(:uid, :keys, :statement, :interests)');
    $stmt->bindParam(':uid', $canref, PDO::PARAM_INT);
    $stmt->bindParam(':keys', $cancvkeys, PDO::PARAM_STR);
    $stmt->bindParam(':statement', $cancvstatement, PDO::PARAM_STR);
    $stmt->bindParam(':interests', $cancvinter, PDO::PARAM_STR);    
    try {
        $stmt->execute();
        //print_r($stmt);
        //$result = $stmt->fetchAll();
    }
    catch (Exception $e) {
        echo $e;
    }

Still getting the same error message...

So if I change the word from Keys to kwds, that will fix the problem?

What do you mean, surround it with backticks?

@pritaeas - Well thats 48 hours I will never get back :)
Many thanks for this mate, Is there a list of reserved words I can use to look up if I come across this same issue...

Can't believe I have gone round in circles for two days trying to sort this out...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.