0

My brick wall is that I am running this code on 2 pages.

session_start()
$selectbegindate = $_POST['begindate']; 
$selectenddate = $_POST['enddate']; // End date
$begindate = new DateTime($selectbegindate);
$enddate = new DateTime($selectenddate);

Form:

<form action = "index.php" method="post"><!-- Begin date select form -->
                Begin Date: <input type="date" id="begindate" name="begindate">
                End date: <input type="date" id="enddate" name="enddate">
                <input type="submit" name="submit" value="Submit">
                </form

Immediately below the form and on the test 2nd page I have:

<?php
if(isset($submit)) {
  $_SESSION["begindate"] = $_GET["begindate"];
  $_SESSION["enddate"] = $_GET["enddate"];
}
?> 

First page: I can submit a begin date and an end date through an HTML form and my page works as expected, running SQL statements, producing charts, etc. My issue comes when I navigate to the test page, which has the code above, I get:

Notice: Undefined variable: begindate in C:\xampp\htdocs\dashboard\sessionstest.php on line 14

Line 14 in the test code above.

I'm sure this is a duplicate of PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" but I think what I need is different since the user can change the variables on the next page.

I would like to use SESSION as it seems the most viable.

I have tried understanding isset and isempty but not having any luck applying it to what I need.

Should I use anything in the a href links in the html section?

Thanks for any help.

Edited 6/10/2018 to include the form code.

0 Answers0