Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with syntax i don't have any idea how i fix it. Please help me.

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where idpost= '2'' at line 1
PHP
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$zmienna = "INSERT INTO `comments` (`iduser`, `comment`, `nick_user`) VALUES (:iduser, :comment, :nick_user) where idpost= :idpost ";
$stmt = $PDO->prepare($zmienna);
$stmt->bindValue(':idpost', $article['id'], PDO::PARAM_INT );


What I have tried:

PHP
PDO::PARAM_INT
$zmienna = "INSERT INTO `comments` (`iduser`, `comment`, `nick_user`) VALUES (:iduser, :comment, :nick_user) where idpost= ".$article['id']." ";
Posted
Updated 13-Apr-17 9:35am
v2
Comments
j snooze 13-Apr-17 17:18pm    
extra double quote? Is the 2 supposed to be a string or an integer? if its an integer do you even need those double quotes with the space at the end?
Mike CJ 13-Apr-17 17:27pm    
This is an integer whether I need to remove extra quotes?
j snooze 13-Apr-17 17:43pm    
I would say maybe instead of .$article['id']." "; you should have .$article['id'].;
Don't surround your article id with quotes. Try that.
Mike CJ 13-Apr-17 18:32pm    
Now: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900