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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| <?php
session_start();
// parametre de connexion
$host_name = "localhost";
$database = "forum_projet";
$db_user_name = "root";
$db_password = "root";
// connexion
$conn = mysqli_connect($host_name, $db_user_name, $db_password, $database);
if ($_session=['username']) {
?>
<html>
<head>
<title> home page </title>
</head>
<?php include ("header.php"); ?>
<body>
<form action ="repondre.php" method ="post">
<center>
contenu : <br/>
<textarea style="resize: none ; width:400px;height:300px;"name="contenu_reponse"></textarea>
<br/>
<input type="submit" name="submit" value="post" style="width:400px;">
</center>
</form>
</body>
</html>
<?php
if (isset($_POST['submit'])){
$contenu_reponse=$_POST['contenu_reponse'];
$id_sujet=$_GET['id_sujet'];
$date = date("y-m-d");
$req="insert into reponse(contenu_reponse,createur_reponse,id_sujet,date) VALUES ('".$contenu_reponse."' , '".$_SESSION["username"]."', '".$id_sujet."', '".$date."')" ;
$retour = $conn->query($req);
echo ($retour) ? '<h2> Requete OK</h2>' : '<h2> Requete failled</h2>' ;
}
}
?>
<?php
// On créé la requête
$req = "SELECT * FROM reponse";
// on envoie la requête
$res = $conn->query($req);
//on trace les entetes du tableau
echo "<tr><th> contenu_reponse </th><th> createur_reponse</th></tr>";
// on va scanner tous les tuples un par un
while ($data = mysqli_fetch_array($res)) {
// on affiche les résultats
echo "<tr><td>".$data['contenu_reponse']."</td><td>".$data['createur_reponse']."</td></tr>";
}
//fermeture du tableau
echo "</table>";
?> |
Partager