A.B.
A.B.

Reputation: 2470

php-mysql-pdo: execute not working after prepare when inserting

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

Answers (2)

MillaresRoo
MillaresRoo

Reputation: 3848

Try: "INSERT INTO news (title, content) VALUES (:title, :content)";

You must surround the insert values with parentheses. 

Upvotes: 3

Krish R
Krish R

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

Related Questions