我有一个表格供用户输入信息。表格有4页。第一页是用户输入的客户详细信息,使用POST发送到下一页,第二页发送到“customer”表中的mysql数据库。
但是,接下来的两页都与“雇用”表相关联。使用POST将第2页上的数据移至第3页,使用POST将第3页上的数据移至第4页。
我决定使用会话变量来移动从第2页获取的所有数据并发送到第3页以转移到第4页,我计划将所有租用数据放入数据库,但数据被移动使用SESSION似乎不想转到下一页。
我确定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);
?>
答案 0 :(得分:1)
你的主人是什么人? 有时主机停用会话,这种情况很少见,但可能会发生。我确信您无法使用“免费”主机会话(免费是提供低级主机的法国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';
?>
答案 1 :(得分:0)
我认为你应该在第2页中定义会话变量而不是在第3页