<code>$pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $txt=$_POST["txt"]; $sql="insert into user(txt)values($txt)"; $pdo->exec($sql);</code>
<code>$pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $txt=$_POST["txt"]; $sql="insert into user(txt)values($txt)"; $pdo->exec($sql);</code>
<code>$sql="insert into user(txt)values('$txt')";</code>
你的txt應該是字串類型的字段,記得加單引號
沒有什麼錯誤提示麼?換種寫法試試
<code>// 预处理 $sql = "INSERT INTO `user`(`txt`) VALUES (:txt)"; $stmt = $pdo->prepare($sql); $stmt->execute([':txt' => $txt]);</code>