我有一个表格供用户输入信息。表格有 4 页。第一页是用户输入的客户详细信息,它使用 POST 发送到下一页,在第二页上发送到“客户”表中的 mysql 数据库。
但是,接下来的两页都链接到“雇用”表。第 2 页上的数据使用 POST 移动到第 3 页,第 3 页上的数据使用 POST 移动到第 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);
?>