我该如何解决这个问题。
这是我的网站
这是完全的错误。
致命错误:在/home/budweiser/public_html/verify.php:13堆栈跟踪:#0 /home/budweiser/public_html/verify.php:#0 /home/budweiser/public_html/verify.php(13):DateTime->_ exception (‘03-22-2016’) #1 /home/budweiser/public_html/verify.php(35):年龄('03-10-1991') #2 {main}抛入第13行的/home/budweiser/public_html/verify.php
我的代码:
<?php
//created date function
function age($dob){
//echo $dob;
$dob = date("m-d-Y", strtotime($dob));
$date1 = new DateTime($dob);
$date2 = new DateTime(date("m-d-Y"));
$interval = $date1->diff($date2);
return $interval->y;
}
//if a form is submitted do the following
if(array_key_exists("submit", $_POST)){
$mm = $_POST["date_"]["month"];
$dd = $_POST["date_"]["day"];
$yyyy = $_POST["date_"]["year"];
$age = age($mm."-".$dd."-".$yyyy);
//check age here
if($age > 17){
//set cookie here and redirect here if you want
session_start();
$_SESSION["old_enough"] = true;
header('Location: http://91.109.247.179/~buddreambig/index.php');
}else{
//redirect here as well
include("verify-age.html");
}
} else {
include("verify-age.html");
}
?>更新代码
新误差
致命错误:在/home/budweiser/public_html/verify.php:11堆栈跟踪:#0 /home/budweiser/public_html/verify.php:11堆栈跟踪:#0 /home/budweiser/public_html/verify.php(11):日期时间-__构造(‘197019701970197.’) #1 /home/budweiser/public_html/verify.php(35):年龄(‘-’) #2 {main}抛入第11行的/home/budweiser/public_html/verify.php
<?php
//created date function
function age($dob){
//echo $dob;
$dob = date("YYYY-MM-DD", strtotime($dob));
$date1 = new DateTime($dob);
$date2 = new DateTime("now");
$interval = $date1->diff($date2);
return $interval->y;
}
//if a form is submitted do the following
if(array_key_exists("submit", $_POST)){
$MM = $_POST["date_"]["month"];
$DD = $_POST["date_"]["day"];
$YYYY = $_POST["date_"]["year"];
$age = age($YYYY."-".$MM."-".$DD);
//check age here
if($age > 17){
//set cookie here and redirect here if you want
session_start();
$_SESSION["old_enough"] = true;
header('Location: http://buddreambig.com/');
}else{
//redirect here as well
include("verify-age.html");
}
} else {
include("verify-age.html");
}
?>发布于 2016-03-22 11:35:23
将age()函数替换为下面。阅读更多原创文章
function age($dob){
//echo $dob;
$date1 = new DateTime($dob);
$date2 = new DateTime("now");
$interval = $date1->diff($date2);
return $interval->y;
}发布于 2016-03-22 13:27:02
这个问题现在已经解决了。
我刚删除了函数的第一行
谢谢大家。
https://stackoverflow.com/questions/36153046
复制相似问题