Bonjour,
Dans la page commentaires.php,j'ai un formulaire qui une qu'on clique sur "envoyer" il dirige sur la page commentaires_post.php qui le redirige sur la page commentaires.php en affichant le mot en question envoyer dans le formulaire.
Alors voilà le scrip "commentaires.php":
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<title>blog</title>
</head>
<body>
<h1>Mon blog !</h1>
<p><a href="index.php">Retour à la liste des billets</a></p>
<?php
// on se connecte à la bdd
try{
$bdd = new PDO('mysql:host=localhost;dbname=give','root','');
}
catch(Exception $e){
die('error :'.$e->getMessage());
}
// la requête préparée pour billets
$Bien = $bdd->prepare('SELECT id,titre,contenu,DATE_FORMAT(date_creation,\'%d/%m/%Y à %Hh%imin%ss\') AS date_creation FROM billets WHERE id = ?');
$Bien->execute(array($_GET'billets'])) or die(print_r($bdd->errorInfo()));
$Bon = $Bien->fetch();
{
?>
<section>
<h3><?php echo htmlspecialchars($Bon'titre']);?>
<em><?php echo $Bon'date_creation'];?></em>
</h3>
<p><?php echo htmlspecialchars($Bon'contenu']);?></p>
</section>
<section>
<h2>Commentaires</h2>
<?php
// la requête préparée commentaires
}
$Bien->closeCursor(); // stop la requête billets avent....
$Ben = $bdd->prepare('SELECT auteur,commentaire,DATE_FORMAT(date_commentaire,\'%d/%m/%Y à %Hh%imin%ss\') AS date_commentaire FROM commentaires WHERE id_billet = ? ORDER BY date_commentaire');
$Ben->execute(array($_GET'billets'])) ;
//la boucle pour afficher tous les commentaires....
while($Bon = $Ben->fetch())
{
?>
<p><strong><?php echo htmlspecialchars($Bon'auteur']);?></strong>
le <em><?php echo $Bon'date_commentaire'];?></em> </p>
<p> <?php echo htmlspecialchars($Bon'commentaire']);?> </p>
<?php
}
$Ben->closeCursor(); // stopper la requête commentaire....
?>
<br/>
<fieldset>
<legend>Message</legend>
<form action="commentaires_post.php" method="post">
<label for="auteur">auteur</label>:<input type="text" name="auteur" id="auteur"/> <br/> <br/>
<textarea name="message">
ton commentaire ici...
</textarea> <br/>
<input type="submit" value="Envoyer"/>
</form>
</fieldset>
</section>
</body>
</html>
Et maintenant le scrip de la page "commentaires_post.php":
<?php
// on se connecte à la bdd
try
{
$bdd = new PDO('mysql:host=localhost;dbname=give','root','');
}
catch(Exception $e)
{
die('error :'.$e->getMessage());
}
// la requête préparée
$req = $bdd->prepare('INSERT INTO commentaires(auteur,commentaire,date_commentaire) VALUES(?, ?, ?)');
$req->execute(array('auteur'=>$_POST'auteur'],'commentaire'=>$_POST'message'],'date_commentaire'=>$_POST'date_commentaire'])) ;
// on redirige vers la page commentaire
header('location:commentaires.php');
$req->closeCursor();// on stop la requête
?>
Mais une erreur se présente.Ce qui est la cause de ce post alors,vos aides me serra bénéfique!L'erreur:
( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: billets in C:\wamp\www\nouvo\commentaires.php on line 26
( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: billets in C:\wamp\www\nouvo\commentaires.php on line 50