I have a form for users to input information into. There are 4 pages to the form. The first page is customer details that users input, which uses POST to send to the next page and on the second page are sent to the mysql database in the "customer" table.
However, the next two pages are both linked to the "hire" table. The data on page 2 is moved to page 3 using POST and data on page 3 is moved to page 4 using POST.
I decided to use session variables to move all the data taken from page 2 and sent to page 3 to move to page 4, where i planned that all the hire data would then be put into the database, however the data being moved using SESSION doesn't seem to want to move to the next page.
I know for sure that the POST method is working and entering the data into the database is working, but it isnt the correct data (e.g time is just 00:00:00), meaning the variables aren't moving across the pages. i've searched around but i'm struggling, and i'm new to php so i have only just found out about session variables!
Any help is welcomed.
The third form code:
<?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();
?>
The fourth and final page code:
<?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);
?>
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.