TAS-ALFA/blog-post/comment.php

23 lines
818 B
PHP
Raw Normal View History

<?php if( !isset( $_SESSION ) ) session_start();
2018-12-06 00:58:20 +01:00
include "../settings/db_connect.php";
$_SESSION['message'] = '';
2018-12-12 21:20:00 +01:00
$post=$_GET['post'];
$user=$_SESSION['user'];
2018-12-06 00:58:20 +01:00
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$tekst = $mysqli->real_escape_string($_POST['tekst']);
$_SESSION['tekst'] = $tekst;
$sql = "INSERT INTO comments (post_id, username, tekst)"
. "Values ('$post' , '$user' , '$tekst')";
2018-12-06 00:58:20 +01:00
if($mysqli->query($sql) === true){
$_SESSION['message'] = "Dodanie komentarza się powiodło!";
2018-12-12 21:20:00 +01:00
header("location:post.php?post=$post");
2018-12-06 00:58:20 +01:00
}
else{
$_SESSION['message'] = "Nie udało się dodać komentarza!";
}
}
?>