Hello,
I’ve a very simple chat that’s working.
There’s 2 files.
I add this one on the about page of the basic app Yii :
<?php
setlocale(LC_TIME, 'fr_FR');
$date = strftime('%d/%m/%Y %H:%M:%S');
echo "Nous somme le : $date";
$today = date("Y-m-d H:i:s");
?>
<center>
<form action="cible.php" method="post">
<p>
<label for="pseudo">Pseudo</label> : <input type="text" name="pseudo" /><br />
<label for="message">Message</label> : <input type="text" name="message"/><br />
<input type="hidden" name="date" value="<?php echo $today ?>" />
<input type="submit" value="Valider" />
</p>
</form>
</center>
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=chat', 'user', 'pwd');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT pseudo, message, date FROM minichat ORDER BY date DESC LIMIT 10');
while ($donnees = $reponse->fetch())
{
echo '<p><strong>' . htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['message']) . htmlspecialchars($donnees['date']) . '</p>';
}
$reponse->closeCursor();
?>
And this one is on the views directory :
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=chat', 'user', 'pwd');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$req = $bdd->prepare('INSERT INTO minichat (pseudo, message, date) VALUES(?, ?, ?)');
$req->execute(array($_POST['pseudo'], $_POST['message'], $_POST['date']));
header('Location: about.php');
?>
I add this to the controller :
public function actionCible()
{
return $this->render('cible');
}
But I have a 404 error when I submit the form.
I don’t understand why.
If someone could help please ?
Cordially,
ANDRE Ani