PHP:MySQL插入不工作
我不明白为什么我的insert into查询不起作用。。。这是我的密码:PHP:MySQL插入不工作,php,mysql,insert,pdo,Php,Mysql,Insert,Pdo,我不明白为什么我的insert into查询不起作用。。。这是我的密码: <?php session_start(); try { $bdd = new PDO('mysql:host=localhost;dbname=gestion', 'root', ''); } catch(Exception $e) { die('Erreur : '.$e->getMessage()); } $req = $bdd->prepare('INSERT INTO tasks (title
<?php
session_start();
try
{
$bdd = new PDO('mysql:host=localhost;dbname=gestion', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$req = $bdd->prepare('INSERT INTO tasks (title, details, maturity, from, to) VALUES(:title, :details, :maturity, :from, :to)');
$req->execute(array(
':title'=>$_POST['title'],
':details'=>$_POST['details'],
':maturity'=>$_POST['maturity'],
':from'=>$_SESSION['login'],
':to'=>$_POST['to']
));
header('Location: tasks.php');
?>
运行此代码时不会发生任何事情
谢谢你的帮助
答复:
FROM
和TO
都是保留字。。。所以,我不能这样使用它们。from和to是mysql中的保留关键字
您可以在mysql中使用“from”和“to”……但是您必须用以下字符包装它们:`(键盘顶部1键的左侧)
所以写'from'代替from,'to'代替to
from
和to
都是。您需要用倒钩引用它们作为列名。您能捕获sql错误吗?删除标题()
并检查错误消息。@Bigood这是PDO。所以OP需要检查print\r($bdd->errorInfo())
@MichaelBerkowski我的坏,刚刚编辑!