【问题标题】:Substracting birthday year with the current year用当前年份减去生日年份
【发布时间】:2013-09-26 10:23:30
【问题描述】:

我已经开始学习 PHP,只是不知道如何完成。 基本问题是如何从当年计算年龄..

我必须使用提交按钮来完成,这就是我的问题。我试过这个:

<form name="form2" action="16.1.php" method="POST">
Birthday year:
<input type="post" name="post">
<input type="submit" value= "Verstuur" >
</form>

16.1php:

<?php
echo date ('Y') - $_POST['post'];
?>

【问题讨论】:

  • 你得到了什么错误?

标签: php forms post submit subtraction


【解决方案1】:

尝试更新这个..

<input type="input" name="post">

type = "post"type = "input"

【讨论】:

  • 谢谢.. 没想到这么简单。 :)
【解决方案2】:

试试这个

如果($_POST['提交'])

{
$byear = $_POST['bdate']; 
$today = new DateTime();
$birthdate = new DateTime($byear);
$interval = $today->diff($birthdate);
echo $interval->format('%y years');
}

<form name="form2" action="" method="POST">
Birthday year:
<input type="text" name="bdate">(yyy-mm-dd)
<input type="submit" name="submit" value= "Verstuur" >
</form>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 2021-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    相关资源
    最近更新 更多