1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
<?php
// index.php - j'affiche tous les billets présents dans la base
require_once("Billet.class.php");
include("fonctions.inc");
session_start();
if(!isset($_SESSION["billets"]))
$_SESSION["billets"] = getAll();
foreach($_SESSION["billets"] as $b)
{ ?>
<section>
<a href="affiche_billet.php?id=<?php echo $b->getId(); ?>"><?php echo $b->getTitre(); ?></a><br>
<?php echo $b->getTexte(); ?>
</section>
<?php
}
//insert.php - insertion d'un nouveau billet
require_once("Billet.class.php");
include("fonctions.inc");
session_start();
try{
$bdd = connectBdd();
$result = $bdd->exec('insert into billets values("","'.$_POST["titre"].'","'.date("y-m-d").'","","'.$_POST["texte"].'","'.$_POST["image"].'")')
or die(print_r($bdd->errorInfo()));
if($result == 1)
{
$id = $bdd->lastInsertId();
$bdd = null;
$_SESSION["billets"][] = new Billet($id, $_POST["titre"], $_POST["texte"]);
header('Location:index.php');
}
else header('Location:affiche_billet.php');
}
catch(Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
?> |
Partager