inseretion et redirection vers la page index.php
Posté : 20 sept. 2018, 20:37
Bonjour , je suis en train de creé un forum , je fais l'insertion dans une table qui contienne 5 champs (id s'inscrémente auto) depuis un formulaire dans la page index.php par la methode POST , et là je suis dans la page commentaires.php qui redérige vers la page index.php aprés l'insertion , mais je trouve que ça marche pas ! voila les messages d'erreur :
,
voici le code de l page commentaires.php :
( ! ) Notice: Undefined variable: dd in C:\wamp\www\Debutant\commentaires_post.php on line 23
( ! ) Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\wamp\www\Debutant\commentaires_post.php on line 23
( ! ) Error: Call to a member function prepare() on null in C:\wamp\www\Debutant\commentaires_post.php on line 23
line 23 : $req = $dd->prepare('INSERT INTO commentaires (auteur,commentaire) VALUES (? , ?)');
,
voici le code de l page commentaires.php :
<!DOCTYPE html>
<html>
<head>
<title> Page d'envoi du Formulaire </title>
</head>
<body>
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=blog','root','',array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch(Exception $e)
{
die('erreur : ' . $e->getMessage() ) ;
}
$req = $dd->prepare('INSERT INTO commentaires (auteur,commentaire) VALUES (? , ?)');
$req -> execute(array($_POST['auteur'],$_POST['commentaire']));
header('location: commantaires.php');
?>
</body>
</html>