使用PHP显示html输入的数据

时间:2018-10-12 12:16:19

标签: php html

下面是我的HTML和PHP代码。我正在尝试显示输入的数据,但是我什么也没得到。我的代码有什么问题?

HTML

<form action="welcome.php" method="POST">
        <fieldset>
            <legend> Personal Details: </legend>
                <label for="fname>"></label>
                    <input type="text" name="Name" id="fname" required autofocus placeholder="First Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
                <label for="lname>"></label>
                    <input type="text" name="Last Name" id="lname" required autofocus placeholder="Last Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
                <label for="email">Email: </label>
                    <input type="text" name="email" id="email" required placeholder="Your school email" pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z{2} title="Please enter a valid email address>
                <label for="phone">Phone: </label>
                    <input type="tel" name="phone" id="phone" required placeholder="Please enter in your phone number" pattern="[0-9]{4} [0-9]{3} [0-9]{3}" title="Please enter in a phone number in this format: #### ### ###">
            <select name="country" required>
                <option value=""> </option> 
                <option value="US">US</option>
                <option value="UK">UK</option>
                <option value="AUS">AUS</option>
            </select>
        </fieldset>
        <br>
        <fieldset>
            <legend> Booking Details: </legend>
            <input type="date" name="date" min="2018-10-07" max="2018-10-31">
            <input type=time min=9:00 max=17:00 step=900> 
            <br>
            <br>
            <label for="dorm">Dormitory: </label>
            <br>
            <select name="dorm" required>Dormitory
                <option value="Cypress">Cypress Hall</option>
            </select>
            <br>
            <br>
            <label for="floor">Floor: </label>
            <br>
            <select name="floor" required>Floor: 
                <option value=""></option>
                <option value="02">02</option>
                <option value="03">03</option>
                <option value="04">04</option>
                <option value="05">05</option>
                <option value="06">06</option>
                <option value="07">07</option>
                <option value="08">08</option>
            </select>
            <br>
            <br>
            <label for="roomnumber">Room Number: </label>
            <br>
            <select name="roomnumber">Room Number: 
                <option value=""></option>
                <option value="22">22</option>
            </select>
            <br>
            <br>
            <label for="roomletter">Room Letter: </label>
            <br>
            <select name="roomletter" required="">Room Letter
                <option value=""></option>
                <option value="A">A</option>
                <option value="B"> B</option>
            </select>
            <br>
            <br>
            <label for="bedroomcleaning">Bedroom: </label><br>
            <input type="checkbox" id="box-4" onclick="checkPrice()" value="4">Dust all ceiling fans/light/fixtures within reach.<br>
            <input type="checkbox" id="box-5" onclick="checkPrice()" value="5"> Change sheets and/or fold clothes if requested by client.<br>
            <input type="checkbox" id="box-6" onclick="checkPrice()" value="6"> Straighten up, put toys away, make beds, fold clothes and put on bed. Straighten papers and put in a pile. DO NOT THROW AWAY ANY PERSONAL ITEMS!<br><br>
            <label for="bathroomcleaning">Bathroom: </label><br>
            <input type="checkbox" id="box-1" onclick="checkPrice()" value="1"> Clean bowl and wipe down toilet cover, seat, under seat, base and behind the base.<br>
            <input type="checkbox" id="box-2" onclick="checkPrice()" value="2"> Clean all mirrors.<br>
            <input type="checkbox" id="box-3" onclick="checkPrice()" value="3"> Clean countertops and backsplashes.<br>
            <label for="bathroomprice" id="price">Total Price: </label>

            <br>
            <br>
            <input type="submit">
        </fieldset>
        </form>

PHP

Welcome <?php echo $_POST["Name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
Your phone number is: <?php echo $_POST["phone"]; ?>

2 个答案:

答案 0 :(得分:0)

检查您的电子邮件输入模式:

[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z{2}

[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2}

也:

<input type=time min=9:00 max=17:00 step=900> 

<input type="time" min="9:00" max="17:00" step="900"> 

答案 1 :(得分:-1)

正如乔恩在评论中所说,您需要一个

div。

<form action="yourPhpPage.php" method="POST">
    <label ...>...</label>
    <input ... />
    ...
    <input type="submit" value="Send" />
</form>
  • action属性指示提交表单时要调用的页面。
  • method告诉您如何发送数据(主要是GET或POST)
  • <input type="submit" />是提交按钮。当您单击它时,将用不同输入的值调用action中指示的页面。提交输入的值就是显示的内容。

最终您可以使用提交<button>了:

<button type="submit">What you want to be displayed on it.</button>

我更喜欢这个,因为使用CSS和JS分别修改其样式和行为更容易。但这不是重点。

希望对您有帮助!
让·马克。