-1
我尝试将表单的数据存储到数据库中。我无法弄清楚为什么这段代码不工作......没有任何反应。 谢谢你的帮助。 这里是我的代码:PHP:使用准备工作,不工作
<?php
// Connexion à la base de données
try
{
$bdd = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
// Insertion du message à l'aide d'une requête préparée
$auteur="Henri";
$req = $bdd->prepare('INSERT INTO factures (projet, fournisseur, montant, ref, in_out, commentaires, auteur, input_date, maturity) VALUES(:projet, :fournisseur, :montant, :ref, :in_out, :commentaires, :auteur, CURDATE(), :maturity');
$req->execute(array(
'projet'=>$_POST['projet'],
'fournisseur'=>$_POST['fournisseur'],
'montant'=>$_POST['montant'],
'ref'=>$_POST['ref'],
'in_out'=>$_POST['in_out'],
'commentaires'=>$_POST['commentaires'],
'auteur'=>$auteur,
'maturity'=>$_POST['maturity']
));
header('Location: index.php');
?>
正确的代码: - '谟'=> $ _ POST [ '谟']必须是 ':谟'=> $ _ POST [ '谟'], - 有在VALUES SQL查询结束时是缺失的)。
我做了你的建议,但数据库仍然是空的... – Henri 2013-03-04 22:05:49
没有任何反应。 – Henri 2013-03-04 22:09:34
优秀!试着围绕你的字段名称用' – christopher 2013-03-04 22:18:07