I want to make button that only appears when you make a post but after you reload page or click the button that button disappear. The button should redirect you to page with your posts. I tried to make it with SESSION but it doesn't seem to work. Can you guys post how would you do that. EDIT: I fixed typing mistake, still nothing shows up.
<?php
session_start();
include ('init.php');
if(isset($_POST['error'])){
echo($_SESSION['error']);
unset($_SESSION['error']);
}
if(isset($_POST['success'])){
header('location: index.php');
}
if(isset($_POST['submit'])){
$title = $Users->checkInput($_POST['title']);
$text = $Users->checkInput($_POST['text']);
if($Post->postMessage($title,$text)){
$_SESSION['error'] = '<input type="submit" name="success">'; /* Session with input i want to show only once */
header('location: POST.php');
return;
}
}
?>
<html>
<head><title></title></head>
<body>
<form method='POST'>
Title: <input type="text" name="title">
Text: <input type="text" name="text">
<input type="submit" name="submit">
</form>
<a href="index.php">Go back</a>
</body>
</html>
This is my class file:
class Post extends Users{
public function postMessage($title,$text){
$sql = "INSERT INTO forum(title,text,date,forum_id) values(:title,:text,:date,:forum_id)";
$stmt = $this->pdo->prepare($sql);
$stmt->execute(array(
':title' => $title,
':text' => $text,
':date' => date('Y-m-d H:i:s'),
':forum_id' => $_SESSION['id']
));
return true;
}
}