0

I'm working on a reservation system, and am stuck. I'd like the user to submit values from an HTML form and then send the values to a different PHP file to check the inputs with MYSQL statements to check for potential scheduling conflicts.

Currently, the user enters the start and end dates, and then the amount of sessions they want on each day. I display the same fields for each session the user enters for that day. I use arrays to store and get the values.

The only thing I can't figure out is how to display the error messages on the form after the user submits the values and they're checked.

Code for the form

<?php
session_start();

$date = $_SESSION['start'];
echo "<html>";
echo "<body>";
echo "<form method=\"POST\" action = \"check.php\">
    // Advances through each day until the end date
    while (strtotime($date) <= strtotime($_SESSION['end'])) {
        // This gets the variable saved from the check page and repopulates fields
        $name = $_SESSION[$date . 'name'];
        echo "<br>";
        echo $date;
        // For loop to display the previously enter amount of sessions on each day
        // Then replace this to $_SESSION['amountofsessionsforthisday']
        for ($i = 0; $i < $_SESSION['amountofsessionsforthisday' . $date]; $i++) {
            echo "<br>";
            // Each value is stored in an array named in the following way: DATE_FIELDNAME ex: 2017-4-21name
// If the checker.php has found an error, $name will be set and can be used to repopulate the form with the same data
            if (isset($name)) {
                foreach( $name as $key => $n ) {
                    echo "        <input type='text' name=\"" . $date . "name[]\" value = \"" . $n . "\" placeholder='Session Name' required/>";
                    echo "        <br>";
                    echo "        <br>";
                    echo "        Format your time input to 24 hour time: HH:MM:SS";
                    echo "        <br>";
                    echo "        <input type='text' name=\"" . $date . "starttime[]\" placeholder='Session Start Time' required/>";
                    echo "        <input type='text' name=\"" . $date . "endtime[]\" placeholder='Session End Time' required/>";
                    echo "        <br>";
                    echo "        <select name=\"" . $date . "room[]\">\n";
                    echo "            <option value='1001'>1001</option>\n";
                    echo "            <option value='1002'>1002</option>\n";
                    echo "            <option value='1003'>1003</option>\n";
                    echo "        </select>\n";
                    echo "        <br>";
                    echo "         <input type='number' name=\"beds" . $date . "[]\" placeholder='Beds' required/>";
                    echo "         <br>";
                    echo "         <input type='number' name=\"towels" . $date . "[]\" placeholder='Towels' required/>";
                    echo "         <br>";
                    echo "         <input type='number' name=\"occupants" . $date . "[]\" placeholder='occupants' required/>";
                    echo "         <br>";
                    echo "         <input type='number' name=\"pets" . $date . "[]\" placeholder='pets' required/>";
                    echo "         <br>";
                }
            }

        }

        // Advance to next day
        $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
    }
    ?>
    <input type = "submit" value = "Submit"/><br />
</form>

</body>
</html>

Code for the check.php that will perform the MYSQL checks and send back errors

<?php
$date = $_SESSION['start'];
while (strtotime($date) <= strtotime($_SESSION['conference_end'])) {
    $_SESSION[$date . 'name'] = $_POST[$date . 'name'];
    /// Get other inputs from form
    /// Check inputs for scheduling conflicts with MYSQL
    /// If any form entry has error, send it back to previous form displaying error by the form input
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}
header("Location:add.php");

?>
  • Missing ending quote and semicolon in the line where you start the form – Qirel Apr 28 '17 at 17:56
  • 1
    Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Qirel Apr 28 '17 at 17:59
  • How/where do you expect check.php to send anything back? You might add parameters to the add.php redirect, but wouldn't it be better just to have the checks within add.php so you can detect the errors and display them there? – Sloan Thrasher Apr 28 '17 at 18:04

0 Answers0