0

我是 php 新手,所以也许我的问题很简单。假设我有以下

索引.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<form name="quiz" method="post" action="includes/process.php">
First Name: <input type="text" name="firstname" id="fname"/><span>*</span>
<p></p>
Last Name: <input type="text" name="lastname" id="lname"/><span>*</span>
<input type="submit" name="submit" value="Go"></input>
</form>
</body>
</html>

然后我想将数据发布到下一页:

进程.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Form Post</title>
<body>
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname']; 
echo "my name is $firstname<br/>";
echo "my lastname is $lastname<br/>";
?>
</body>
</html>

现在我的问题是如何再次获取 process.php 的数据并将它们发布到另一个 php 页面,或者将它们保存在 mysql 数据库中?有没有关于如何获取或使用发布数据的教程?

4

1 回答 1

1

您可以使用Sessions来存储数据。

<?php
session_start();
if (isset($_POST['firstname'], $_POST['lastname'])) {
// Store session data
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
}
?>

然后再次取回数据。

<?php
session_start();
if (!isset($_SESSION)) {
// Get session data
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
echo $firstname;
echo $lastname;
}
?>

或将其与链接一起传递

<a href="nextpage.php?firstname=<?php echo $firstname ?>&lastname=<?php echo $lastname ?>" >nextpage</a> 

然后再次取回数据

<?php
if (isset($_GET['firstname'], $_GET['lastname'])) {
// Get variables passed with link
$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];
echo $firstname;
echo $lastname;
}
?>
于 2013-08-03T18:32:46.253 回答