0

所以这里首先是 settings.php 的代码。

<html>
<head><title></title></head>
<body>
<a href="mainpage.php">Main Page</a>
<a href="tictactoe.php">Game</a>
<a href="logout.php">Logout</a>

<form action="mainpage.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Bio: <input type="text" name="bio"><br>
Hobbies: <input type="text" name="hobbies"><br>
Past School: <input type="text" name="past"><br>
Work History: <input type="text" name="work"><br>
<input type="submit">
</form>

</body>
</html>

我正在尝试获取从该页面提交到 mainpage.php 的所有值以保存,以便当我单击另一个链接然后返回时,它仍然存在。这是我的 mainpage.php 的代码

<html>
<head><title></title></head>
<body>
<a href="settings.php">Settings</a>
<a href="tictactoe.php">Game</a>
<a href="logout.php">Logout</a>
</body>
</html>

<?php
if (!empty($_POST)){

 $name = $_POST['name'];
 $email = $_POST['email'];
 $bio = $_POST['bio'];
 $hobbies = $_POST['hobbies'];
 $past = $_POST['past'];
 $work = $_POST['work'];

 echo "<br>";
 echo "My name is: " . $name . "<br />";
 echo "My email is: " . $email . "<br />";
 echo "A bit about myself: " . $bio . "<br />";
 echo "These are my hobbies: " . $hobbies . "<br />";
 echo "These are past school: " . $past . "<br />";
 echo "These are my past work: " . $work . "<br />";
}
?>

有什么建议么?

4

3 回答 3

1

请通过手册链接,http ://php.net/manual/en/book.mysqli.php

计划是,

  1. 根据您的设计创建数据库和表,

  2. 建立数据库之间的连接

  3. 添加插入查询

  4. 从数据库中检索插入的记录并使用 php 以 HTML 格式显示。

于 2013-11-07T04:04:56.110 回答
0

如果这只是您应用程序中的一种形式,您可以在不使用任何数据库的情况下使用基于文件的存储。您可以将表单信息存储在特定文件夹中的文件中,然后您可以从文件中存储和检索表单值。您可以参考以下链接
https://forums.digitalpoint.com/threads/save-php-form-data-to-a-txt-file.757223/

于 2013-11-07T04:26:23.990 回答
0
<html>
<head><title></title></head>
<body>
<a href="settings.php">Settings</a>
<a href="tictactoe.php">Game</a>
<a href="logout.php">Logout</a>
</body>
</html>

<?php
session_start();
if (!empty($_POST)){

 $_SESSION['form_data']['name'] = $name = $_POST['name'];
 $_SESSION['form_data']['email'] = $email = $_POST['email'];
 $_SESSION['form_data']['bio']  = $bio = $_POST['bio'];
 $_SESSION['form_data']['hobbies'] = $hobbies = $_POST['hobbies'];
 $_SESSION['form_data']['past'] = $past = $_POST['past'];
 $_SESSION['form_data']['work'] = $work = $_POST['work'];

} else if(!empty($_SESSION['form_data']) && empty($_POST)){

    $name = $_SESSION['form_data']['name'];
    $email = $_SESSION['form_data']['email'];
    $bio = $_SESSION['form_data']['bio'];
    $hobbies = $_SESSION['form_data']['hobbies'];
    $past = $_POST['past'];
    $work = $_SESSION['form_data']['work'];
}
 echo "<br>";
 echo "My name is: " . $name . "<br />";
 echo "My email is: " . $email . "<br />";
 echo "A bit about myself: " . $bio . "<br />";
 echo "These are my hobbies: " . $hobbies . "<br />";
 echo "These are past school: " . $past . "<br />";
 echo "These are my past work: " . $work . "<br />";
}
?>
于 2013-11-07T04:09:21.993 回答