par
rjuan » 19 nov. 2013, 14:02
bonjour,
Je ne comprends pas pourquoi je ne peux insérer une nouvelle entrée dans ma base avec ces deux pages :
La première appelant la seconde.
Page "minichat.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>
<title>Mini-chat</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
form
{
text-align:center;
}
</style>
<body>
<form action="minichat_post.php" method="post">
<p>
<label for="nom">Nom</label> : <input type="text" name="nom" id="nom" /><br />
<label for="message">Message</label> : <input type="text" name="message" id="message" /><br /><br />
<input type="submit" value="Envoyer" />
</p>
<?php
include('db_connect.php');
$bdd= \Connection();
$reponse = $bdd->query('SELECT nom, message FROM minichat ORDER BY ID DESC LIMIT 0, 10');
while ($donnees = $reponse->fetch())
{
echo '<p><strong>' . htmlspecialchars($donnees['nom']) . '</strong> : ' . htmlspecialchars($donnees['message']) . '</p>';
}
$reponse->closeCursor();
?>
</form>
</body>
</html>
et la seconde ("minichat_post.php") :
<?php
/**
* Description:
* insère le message reçu par $_POST
* et redirige vers minichat.php
*/
//appelé par Mininchat après connection, on sait que $bdd est initialisé.
// insertion de la requète
if (isset($_POST['Envoyer']) && isset($_POST['nom']) && isset($_POST['message']))
{
$req=$bdd->prepare('INSERT INTO minichat (id,pseudo,message) VALUES (:id,:nom, :message)');
$req=$bdd->exec(array(
'',
$_POST['nom'],
$_POST['message']
));
}
//
// redirection vers le script appelant
header('Location:minichat.php');
?>
bonjour,
Je ne comprends pas pourquoi je ne peux insérer une nouvelle entrée dans ma base avec ces deux pages :
La première appelant la seconde.
Page "minichat.php" :
[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>
<title>Mini-chat</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
form
{
text-align:center;
}
</style>
<body>
<form action="minichat_post.php" method="post">
<p>
<label for="nom">Nom</label> : <input type="text" name="nom" id="nom" /><br />
<label for="message">Message</label> : <input type="text" name="message" id="message" /><br /><br />
<input type="submit" value="Envoyer" />
</p>
<?php
include('db_connect.php');
$bdd= \Connection();
$reponse = $bdd->query('SELECT nom, message FROM minichat ORDER BY ID DESC LIMIT 0, 10');
while ($donnees = $reponse->fetch())
{
echo '<p><strong>' . htmlspecialchars($donnees['nom']) . '</strong> : ' . htmlspecialchars($donnees['message']) . '</p>';
}
$reponse->closeCursor();
?>
</form>
</body>
</html>[/php]
et la seconde ("minichat_post.php") :
[php]<?php
/**
* Description:
* insère le message reçu par $_POST
* et redirige vers minichat.php
*/
//appelé par Mininchat après connection, on sait que $bdd est initialisé.
// insertion de la requète
if (isset($_POST['Envoyer']) && isset($_POST['nom']) && isset($_POST['message']))
{
$req=$bdd->prepare('INSERT INTO minichat (id,pseudo,message) VALUES (:id,:nom, :message)');
$req=$bdd->exec(array(
'',
$_POST['nom'],
$_POST['message']
));
}
//
// redirection vers le script appelant
header('Location:minichat.php');
?>
[/php]