sql 不会“执行”INSERT INTO 语句,但代码工作起来很奇怪


sql doesnt 'execute' INSERT INTO statement..but the code weirdly works

<?php

if(isset($_POST["submit"])){
include 'db.php';
$title=$_POST['title'];
$desc=$_POST['desc'];
try{
$sql=" INSERT INTO posttbl (title,desc)
VALUES ('$title','$desc')" ;
$e=$pdo->exec($sql);
}catch (PDOexception $e){
$error="error inserting";
include 'error.php';
exit();
}
header('Location:/test/');


}
?>
*/////////FORM
<html>
<body>
<h3>Add item</h3>
<form action="" method="POST">
Title: <input type="text" name="title"><br />
Item Description: <textarea name="desc" id="comment" type="text"></textarea><br />
<input name="submit" type="submit" value="Submit" />  
</form>

代码正在工作,但它没有在我的数据库中插入任何东西。我错过了什么吗?还是做某事不对?我的数据库由 3 列组成。帖子,标题和描述那怎么了呢?是 if isset($_POST["submit"])){???还是别的什么?

这是将

行插入PDO的正确语法

try {
$var = array(
  'title' => $title,
  'desc' => $desc
);
$req = $bdd->prepare("INSERT INTO posttbl (title,desc) VALUE (:title,:desc)");
$req->execute($var);} catch (Exception $e) {    
echo $e->getMessage();}