1

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);
?>
6
  • it looks as though your third form is deleting whatever is in each session variable. Since I can't see all the code for form 3, all I can say is if $time is not defined, then you are placing NULL in $_SESSION['time']. Commented Jan 24, 2013 at 21:10
  • show some more code from form 3 Commented Jan 24, 2013 at 21:11
  • 1
    also, you could try storing an array in your session: $_SESSION['customer'] = array('name'=>$name); Commented Jan 24, 2013 at 21:14
  • and a commonly used debugging tool is to just do var_dump($_SESSION); die(); to dump out whats stored in your session and trace the problem Commented Jan 24, 2013 at 21:14
  • Please, don't use 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. Commented Jan 24, 2013 at 21:27

2 Answers 2

1

What is your host ? Sometimes hosts deactivate session, it's really rare but can happen. I know for sure that you could not use session with 'free' host (free is a french FAI who provides low level host).

Go grab some informations about your host.

If you want to be sure that sessions works really fine with PHP, do two testings pages.

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';
?>
Sign up to request clarification or add additional context in comments.

2 Comments

i get 'Earth is our mother'
hmm well that's good to know, but i'm not sure why it's not working in my program :c
0

I think you should define session variables in page 2 not in page 3

15 Comments

on page 2 the variables are sent to page 3 using post and then i put that data in to variables on that page and put those variables into session variables, if i used session variables on page 2 wouldnt that make the POST variables pointless?
Sorry I misunderstood . That will be pointless. can you add var_dump($_POST) in page 3 and show me the result?
array(17) { ["time"]=> &NULL ["date"]=> &NULL ["length"]=> &NULL ["numberofpeople"]=> &NULL ["pickuplocation"]=> &NULL ["destination"]=> &NULL ["useofbus"]=> &NULL ["day"]=> &bool(false) ["month"]=> &bool(false) ["year"]=> &bool(false) ["cost"]=> &float(5) ["customerid"]=> &int(57) ["driverid"]=> &int(5) ["endtime"]=> &string(13) "01:00:00 " ["test"]=> &string(19) "Earth is our mother" ["customer"]=> &array(14) { ["time"]=> NULL ["date"]=> NULL ["length"]=> NULL ["numberofpeople"]=> NULL ["pickuplocation"]=> NULL
["destination"]=> NULL ["useofbus"]=> NULL ["day"]=> bool(false) ["month"]=> bool(false) ["year"]=> bool(false) ["cost"]=> float(5) ["customerid"]=> int(57) ["driverid"]=> int(5) ["endtime"]=> string(13) "01:00:00 " } ["hire"]=> array(14) { ["time"]=> NULL ["date"]=> NULL ["length"]=> NULL ["numberofpeople"]=> NULL ["pickuplocation"]=> NULL ["destination"]=> NULL ["useofbus"]=> NULL ["day"]=> bool(false) ["month"]=> bool(false) ["year"]=> bool(false) ["cost"]=> float(5) ["customerid"]=> int(57) ["driverid"]=> int(5) ["endtime"]=> string(13) "01:00:00 " } }
yes $_POST is working. Now add var_dump($_SESSION) at the end of page 3 and page 4.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.