我有一个供用户输入信息的表单。表单有4页。第一页是用户输入的客户详细信息,使用POST发送到下一页,第二页发送到mysql数据库的" customer“表中。
但是,接下来的两个页面都链接到“雇用”表。使用POST将第2页上的数据移动到第3页,使用POST将第3页上的数据移动到第4页。
我决定使用会话变量来移动从页面2获取的所有数据,并将其发送到页面3,以移动到页面4,在那里我计划将所有雇用数据放入数据库,但是使用会话移动的数据似乎不想移动到下一页。
我确信POST方法是有效的,向数据库中输入数据也是有效的,但它不是正确的数据(例如,时间只有00:00:00),这意味着变量不会跨页面移动。我到处寻找,但我在苦苦挣扎,而且我是php的新手,所以我对会话变量的了解才刚刚开始!
欢迎任何帮助。
第三种形式代码:
<?php
session_start();
$_SESSION['time'] = $time;
$_SESSION['date'] = $date;
$_SESSION['length'] = $length;
$_SESSION['numberofpeople'] = $numberofpeople;
$_SESSION['pickuplocation'] = $pickuplocation;
$_SESSION['destination'] = $destination;
$_SESSION['useofbus'] = $useofbus;
$_SESSION['day'] = $day;
$_SESSION['month'] = $month;
$_SESSION['year'] = $year;
$_SESSION['cost'] = $cost;
$_SESSION['customerid'] = $customerid;
$_SESSION['driverid'] = $driverid;
$_SESSION['endtime'] = $endtime;
session_write_close();
?>第四页也是最后一页代码:
<?php
session_start();
$time = $_SESSION['time'];
$date = $_SESSION['date'];
$length = $_SESSION['length'];
$numberofpeople = $_SESSION['numberofpeople'];
$pickuplocation = $_SESSION['pickuplocation'];
$destination = $_SESSION['destination'];
$useofbus = $_SESSION['useofbus'];
$day = $_SESSION['day'];
$month = $_SESSION['month'];
$year = $_SESSION['year'];
$cost = $_SESSION['cost'];
$customerid = $_SESSION['customerid'];
$driverid = $_SESSION['driverid'];
$endtime = $_SESSION['endtime'];
session_write_close();
?>
<?php
$payment = $_POST['payment'];
$information = $_POST['information'];
$con = mysql_connect("localhost","busassociation","fishie123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("busassociation", $con);
//INSERT INTO DATABASE
$sql = "INSERT INTO hire (customerid, driverid, time, endtime, date, length, pickuplocation, destination, useofbus, numberofpeople, cost, day, month, year, payment, information) VALUES ('$customerid', '$driverid', '$time', '$endtime', '$date', '$length', '$pickuplocation', '$destination', '$useofbus', '$numberofpeople', '$cost', '$day', '$month', '$year', '$payment', '$information')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "";
mysql_close($con);
?>发布于 2013-01-25 05:11:50
你的主机是什么?有时主机会停用会话,这种情况很少见,但也有可能发生。我确信你不能使用'free‘主机的会话(free是一个提供低级主机的法国FAI )。
去获取一些关于你的主机的信息。
如果你想确保会话在PHP中工作得很好,可以做两个测试页面。
page1.php
<?php session_start(); $_SESSION['test']='Earth is our mother'; ?>page2.php
<?php session_start();
if(isset($_SESSION['test'])) echo $_SESSION['test'];
else echo 'session problem';
?>发布于 2013-01-25 05:26:57
我认为应该在第2页而不是第3页定义会话变量
https://stackoverflow.com/questions/14510718
复制相似问题