我开始学习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'];
?>
答案 0 :(得分:0)
尝试更新此内容..
<input type="input" name="post">
type = "post"
至type = "input"
答案 1 :(得分:0)
试试这个
如果($ _ 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>