1

我有一个表格供用户输入信息。表格有 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);
?>
4

2 回答 2

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';
?>
于 2013-01-24T21:11:50.483 回答
0

我认为您应该在第 2 页而不是在第 3 页中定义会话变量

于 2013-01-24T21:26:56.587 回答