PHP if,else语句.出生确认的形式和日期 [英] PHP if, else statement. Form and date of birth validation

查看:122
本文介绍了PHP if,else语句.出生确认的形式和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写代码,练习PHP if and else语句表单验证.

Im writing code practicing PHP if and else statements and form validation.

基本思想是这样的: 输入名称 DOB 并发送电子邮件并单击提交"按钮后,根据他们输入的DOB ,该按钮会将其引导至:

the basic idea is this: After entering name, DOB , and email and clicking the submit button, Based on the DOB they enter the button leads them to leads to:

-告诉他们他们太小不能喝(notwelcome.php)

-a page telling them they are too young to drink (notwelcome.php)

OR

-告诉他们他们可以点饮料的页面(welcome.php)

-a page telling them they can order a drink (welcome.php)

这两个页​​面(notwelcome.php& welcome.php)从名为 action.php 的单独文件中提取,如下所示:

The 2 pages (notwelcome.php & welcome.php) are pulled from separate file called action.php saved like this:

<?php
include('welcome.php');
include('notwelcome.php');
?>

这是我一直在尝试的..但不起作用.什么也没有发生..好像if else代码即使在那里也没有:(

This is what i have been trying ..but its not working. nothing happens.. Its as if the if else code isnt even there :(

<?php

if ($_POST['submit']) {

    $dob = $_POST['dob'];

    if (isset ($_POST['dob'] )> 12/31/1992) {
        header("Location: notwelcome.php");
} else {
        header("Location: welcome.php");}
}
?>

帮助.我是一个初学者,我在代码中碰到了一个小小的障碍.

Help. Im a beginner and i have hit a small bump in the road in my code.

其他信息:

HTML代码是这样的:

HTML Code is like this:

    <div style="text-align: center;">

        <h2>FORM & PHP</h2>

        <h3>WHINE & DINE</h3>
        <form action="action.php" method="post">
           Full Name: <input type="text" name="name"><br>
           Date of Birth: <input type="date" name="dob"><br>
            E-mail: <input type="text" name="email"><br>
            <input type="submit" data-inline="true" value="Submit">

        </form>
        </div>
    </div>
        </form>

推荐答案

尝试一下.另外,除非您希望在处理表单之前将它们显示在页面上,否则不需要include这些文件.我将检查以确保您具有正确的相对路径.您还希望这样做,以便用户以正确的格式输入DOB.

Try this. Also, you don't need to include those files unless you want them showing up on the page before you process the form. I would check to make sure you have the relative path correct. You would also want to make it so users enter the DOB in the right format.

<?php

if (isset($_POST['dob'])) {

    $dob = $_POST['dob'];

    if ($dob > date("m/d/Y", mktime(0, 0, 0, date('m'), date('d'), date('Y') - 21))) {
        header("Location: notwelcome.php");
    } else {
        header("Location: welcome.php");}
}
?>

这篇关于PHP if,else语句.出生确认的形式和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆