drsqpko5286 2018-09-22 05: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 06: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']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部