Reputation: 2470
I have following lines:
$sql = "INSERT INTO news (title, content) VALUES :title, :content";
$pre = $this->prepare($sql);
$pre->bindValue(":title", "xxx");
$pre->bindValue(":content", "yyy");
$pre->execute();
I get no error, but the query is also not executed (i checked the query log).
I tried following changes desperately:
$t="xxx" and $pre->bindValue(":title", $t); (the same also for y)
$sql = "INSERT INTO `news` (`title`, `content`) VALUES :title, :content";
$sql = "INSERT INTO `news` (`title`, `content`) VALUES ':title', ':content'";
Nothing changes. Funny thing is i get no response, no warning, no error just nothing. But the query is not executed.
I found similar posts but non of them solved my problem.
(about $this
... The code is in a class extended from PDO class.)
Upvotes: 4
Views: 3352
Reputation: 3848
Try: "INSERT INTO news (title, content) VALUES (:title, :content)";
You must surround the insert values with parentheses.
Upvotes: 3
Reputation: 22711
try this, your values should be wrapped inside the values()
"INSERT INTO news (title, content) VALUES (:title, :content)";
instead of
"INSERT INTO news (title, content) VALUES :title, :content";
Upvotes: 4