-1

hi i'm trying to implement a small feature including a price checker (just testing for now!) but when i hit submit nothing is ecohed back to me! here is my code:

<!doctype html>
<head>
    <meta charset="UTF-8">    
    <title>ValleyRangesPriceCheck</title>
    <link REL='stylesheet' TYPE='text/css' HREF='Style.css'>
</head>
<body>
    <form>
        <input type="date" name="check-in">
        <input type="date" name="check-out">
        <input type="number" name="num-of-guests" min="1" max="10" placeholder="Guests">
        <select name="operator">
            <option>Candelight</option>
            <option>Misty Woods</option>
            <option>Beach Mont</option>
        </select>

        <button type="submit" name="submit" value="submit">submit</button>
    </form>
    <p> The Answer Is:</p>
    <?php
        if (isset($_GET['submit'])){
            $result1 = $_GET['check-in'];
            $result2 = $_GET['check-out'];
            $operator = $_GET['operator'];
                switch ($operator){
                    case "Candelight":
                        echo $result1 + $result2;
                        break;
                }
        }
    ?>
</body>
</html>

Thanks for the help!

JJJ
  • 32,902
  • 20
  • 89
  • 102
  • You need to use `action` and `method` attribute in form tag: `
    `. Since the form is submitting to the same page, you can leave `action` blank. [SO: Check this for more info on action in self submitting forms](https://stackoverflow.com/questions/13520127/submit-html-form-on-self-page)
    – Mathews Mathai Mar 24 '18 at 07:19

1 Answers1

1

The form method and action attributes are not defined. You should define where the user data should be posted. Try this code,

<!doctype html>
<head>
    <meta charset="UTF-8">    
    <title>ValleyRangesPriceCheck</title>
    <link REL='stylesheet' TYPE='text/css' HREF='Style.css'>
</head>
<body>
    <form  method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
        <input type="date" name="check-in">
        <input type="date" name="check-out">
        <input type="number" name="num-of-guests" min="1" max="10" placeholder="Guests">
        <select name="operator">
            <option>Candelight</option>
            <option>Misty Woods</option>
            <option>Beach Mont</option>
        </select>

        <button type="submit" name="submit" value="submit">submit</button>
    </form>
    <p> The Answer Is:</p>
    <?php
        if (isset($_GET['submit'])){
            $result1 = $_GET['check-in'];
            $result2 = $_GET['check-out'];
            $operator = $_GET['operator'];
                switch ($operator){
                    case "Candelight":
                        echo $result1 + $result2;
                        break;
                }
        }
    ?>
</body>
</html>
Nadun Kulatunge
  • 1,567
  • 2
  • 20
  • 28