drsqpko5286 2018-09-22 13:59 采纳率: 0%
浏览 73
已采纳

如何在PHP中进行flash会话等flash输入

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;
  }

}
  • 写回答

1条回答 默认 最新

  • donglaogu3788 2018-09-22 14:10
    关注

    I believe that instead of if(isset($_POST['error'])), you should do an isset of $_SESSION, i.e:

    if(isset($_SESSION['error'])){
        echo($_SESSION['error']);
        unset($_SESSION['error']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置