我有 file1.php 和 file2.php。在 file1.php 中,我制作了一个用于添加新闻文章的表单,当我按下“提交”按钮时,输入的数据将发送到 MYSQL 库,页面重定向到 file2.php。我想做的是在 file2.php 中显示这篇文章。我怎样才能做到这一点?
最佳答案
您必须使用 session 来实现此目的。由于您没有在此处发布代码,因此我发布了一个示例。假设这是您的代码。如需更多帮助。请检查这些链接。 1 , 2 , 3 .
文件1.php
<?php
session_start();
if(isset($_POST['article']))
{
//Then you add here in your MySQL
//Similarly add them in the session so you can access the same data on your file2.php
$_SESSION['article'] = $_POST['article'];
//now redirect to file2.php
}
?>
<form action="#" method="POST">
Article :<input type="text" name="article"/>
<input type="submit" value="click"/>
</form>
文件2.php
session_start();
if(isset($_SESSION['article']))
{
echo $_SESSION['article'];
}
关于PHP - 如何在另一个文件中显示以表单输入的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23580634/