PDO statement

can any one spot the syntax issues here i can not see it

// Insert Details to log
	$sth2 = $db->prepare ("INSERT INTO logs (id,to,from,message) VALUES (:id,:to,:from,:message)");
	$sth2->bindParam(':id', $id, PDO::PARAM_INT);
	$sth2->bindParam(':to', $to, PDO::PARAM_INT);
	$sth2->bindParam(':from', $from, PDO::PARAM_INT);
	$sth2->bindParam(':message', $message, PDO::PARAM_INT);
	$sth2->execute();

error i am getting

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 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 'to,from,message) VALUES ('1','4477777777','4477777777','test')'

Why would to, from, and message be integers? I think those would be PDO::PARAM_STR

Second, put it in a try/catch and see what kicks out

try {
// Insert Details to log 
    $sth2 = $db->prepare ("INSERT INTO logs (id,to,from,message) VALUES (:id,:to,:from,:message)"); 
    $sth2->bindParam(':id', $id, PDO::PARAM_INT); 
    $sth2->bindParam(':to', $to, PDO::PARAM_INT); 
    $sth2->bindParam(':from', $from, PDO::PARAM_INT); 
    $sth2->bindParam(':message', $message, PDO::PARAM_STR); 
    $sth2->execute();  
} catch (PDOException $exception) {
    var_dump($exception);
}

again it’s thrown up errors


Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 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 'to,from,message) VALUES ('1','44773345345','447736545','test')' at line 1' in /var/zpanel/hostdata/zadmin/public_html/login/log.php:71
Stack trace:
#0 /var/zpanel/hostdata/zadmin/public_html/login/spoof.php(71): PDOStatement->execute()
#1 {main}
  thrown in /var/zpanel/hostdata/zadmin/public_html/login/spoof.php on line 71

Post the table design for logs, is id an auto-increment column?

id isnt a auto as it’s the id number of the user.

the table is for logging messages

TO and FROM are keywords in MySQL

Try this:

try {
// Insert Details to log 
    $sth2 = $db->prepare ("INSERT INTO logs (id,`to`,`from`,message) VALUES (:id,:to,:from,:message)"); 
    $sth2->bindParam(':id', $id, PDO::PARAM_INT); 
    $sth2->bindParam(':to', $to, PDO::PARAM_INT); 
    $sth2->bindParam(':from', $from, PDO::PARAM_INT); 
    $sth2->bindParam(':message', $message, PDO::PARAM_STR); 
    $sth2->execute();  
} catch (PDOException $exception) {
    var_dump($exception);
}  

that worked spot on thank you very much for that!