所以这里首先是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 />";
}
?>
有什么建议吗?
答案 0 :(得分:1)
请仔细阅读手册链接http://php.net/manual/en/book.mysqli.php
计划是,
根据您的设计创建数据库和表格,
在数据库
添加插入查询
从数据库中检索插入的记录,并使用php以HTML格式显示。
答案 1 :(得分: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 />";
}
?>
答案 2 :(得分:0)
如果这只是应用程序中的一个表单,则可以使用基于文件的存储而无需使用任何数据库。您可以将表单信息存储在特定文件夹中的文件中,然后您可以从文件中存储和检索表单值。您可以参考下面的链接 https://forums.digitalpoint.com/threads/save-php-form-data-to-a-txt-file.757223/