提交按钮不在wordpress页面中工作

时间:2016-04-10 17:53:04

标签: php wordpress

我正在尝试创建一个年龄计算器,它在wordpress中不起作用? http://www.naukridigest.com/age-calculator/ 当按下“提交”时,它会给出错误消息“找不到您请求的页面。”

<html>
<body>
<div style="padding-left:10px;width:575px; height:350px;background-color:yellow;">
<p>Age Calculator</p>

<form action="" method="post">
<table style="border: 1px solid black;border-collapse: collapse;">
    <tr>
    <td style="border: 1px solid black;">Date of Birth:</td>
    <td style="border: 1px solid black;">  
<?php
	$date = 1;
	echo "Date: ";
	echo '<select name="day">';
  for ($date = 1; $date<=31;$date= $date + 1)
  {
	  echo '<option value="'.$date.'">'.$date.'</option>';
  }
	echo "</select>";
  $month = 1;
  echo "Month: ";
  echo '<select name="month">';
  while ($month<=12)
  {
	  echo '<option value="'.$month.'">'.$month.'</option>';
	  $month = $month + 1;
  }
  echo "</select>";
  $currentyear = date ("Y");
  $i = $currentyear;
  echo "Year: ";
  echo '<select name ="year">';
  for ($i = $currentyear;$i>=1950; $i = $i-1)
  {
	  echo '<option value="'.$i.'">'.$i.'</option>';
  }
  echo '</select>'
  ?>
  <input name="submit" type="submit" value="Submit" />

</td></tr>
  <tr>
    <td style="border: 1px solid black;">Age:</td>
    <td style="border: 1px solid black;"><input style="width: 300px;" name="age" type="text"
	value="	<?php
	  if (isset($_POST['submit'])) {
		$day= $_POST["day"];
		$month= $_POST["month"];
		$year= $_POST["year"];
		//echo $name." your date (dd/mm/yyyy) of birth is "."$day"."/"."$month"."/"."$year"."</br>";
	$dob = $year."-".$month."-".$day;
	$birthdate = strtotime($dob);
	//echo "current time".date('y-m-d')."</br>";
	//echo "The time is " . date("h:i:sa")."</br>";

	$DateOfBirth = strtotime($dob);
	$current_time = time();

	global $age_years;
	$age_years = date('Y',$current_time) - date('Y',$DateOfBirth);
	$age_months = date('m',$current_time) - date('m',$DateOfBirth);
	$age_days = date('d',$current_time) - date('d',$DateOfBirth);

	if ($age_days<0) {
		$days_in_month = date('t',$current_time);
		$age_months--;
		$age_days= $days_in_month+$age_days;
	}

	if ($age_months<0) {
		$age_years--;
		$age_months = 12+$age_months;
	}
	echo $age_years." years, ".$age_months." months, ".$age_days." days";  
	  }
?>"/></td>
  </tr>
  <tr>
    <td style="border: 1px solid black;">Age in Years:</td>
    <td style="border: 1px solid black;"><input style="width: 300px;" name="age" type="text"
	value="	<?php
	  if (isset($_POST['submit'])) {
		$day= $_POST["day"];
		$month= $_POST["month"];
		$year= $_POST["year"];
		//echo $name." your date (dd/mm/yyyy) of birth is "."$day"."/"."$month"."/"."$year"."</br>";
	$dob = $year."-".$month."-".$day;
	$birthdate = strtotime($dob);
	//echo "current time".date('y-m-d')."</br>";
	//echo "The time is " . date("h:i:sa")."</br>";

	$DateOfBirth = strtotime($dob);
	$current_time = time();

	global $age_years;
	$age_years = date('Y',$current_time) - date('Y',$DateOfBirth);
	$age_months = date('m',$current_time) - date('m',$DateOfBirth);
	$age_days = date('d',$current_time) - date('d',$DateOfBirth);

	if ($age_days<0) {
		$days_in_month = date('t',$current_time);
		$age_months--;
		$age_days= $days_in_month+$age_days;
	}

	if ($age_months<0) {
		$age_years--;
		$age_months = 12+$age_months;
	}
	echo $age_years." years";  
	  }
?>"/></td>
  </tr>
  <tr>
    <td style="width:120px; border: 1px solid black;">Age in Months:</td>
    <td style="border: 1px solid black;"><input style="width: 300px;" name="age" type="text"
	value="	<?php
	  if (isset($_POST['submit'])) {
		$day= $_POST["day"];
		$month= $_POST["month"];
		$year= $_POST["year"];
		//echo $name." your date (dd/mm/yyyy) of birth is "."$day"."/"."$month"."/"."$year"."</br>";
	$dob = $year."-".$month."-".$day;
	$birthdate = strtotime($dob);
	//echo "current time".date('y-m-d')."</br>";
	//echo "The time is " . date("h:i:sa")."</br>";

	$DateOfBirth = strtotime($dob);
	$current_time = time();

	global $age_years;
	$age_years = date('Y',$current_time) - date('Y',$DateOfBirth);
	$age_months = date('m',$current_time) - date('m',$DateOfBirth);
	$age_days = date('d',$current_time) - date('d',$DateOfBirth);

	if ($age_days<0) {
		$days_in_month = date('t',$current_time);
		$age_months--;
		$age_days= $days_in_month+$age_days;
	}

	if ($age_months<0) {
		$age_years--;
		$age_months = 12+$age_months;
	}
	echo $age_months." months";  
	  }
?>"/></td>
  </tr>
  <tr>
    <td style="border: 1px solid black;">Age in Days:</td>
    <td style="border: 1px solid black;"><input style="width: 300px;" name="age" type="text"
	value="	<?php
	  if (isset($_POST['submit'])) {
		$day= $_POST["day"];
		$month= $_POST["month"];
		$year= $_POST["year"];
		//echo $name." your date (dd/mm/yyyy) of birth is "."$day"."/"."$month"."/"."$year"."</br>";
	$dob = $year."-".$month."-".$day;
	$birthdate = strtotime($dob);
	//echo "current time".date('y-m-d')."</br>";
	//echo "The time is " . date("h:i:sa")."</br>";

	$DateOfBirth = strtotime($dob);
	$current_time = time();

	global $age_years;
	$age_years = date('Y',$current_time) - date('Y',$DateOfBirth);
	$age_months = date('m',$current_time) - date('m',$DateOfBirth);
	$age_days = date('d',$current_time) - date('d',$DateOfBirth);

	if ($age_days<0) {
		$days_in_month = date('t',$current_time);
		$age_months--;
		$age_days= $days_in_month+$age_days;
	}

	if ($age_months<0) {
		$age_years--;
		$age_months = 12+$age_months;
	}
	echo $age_days." days";  
	  }
?>"/></td>
  </tr>
</table>
</form>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

您正在使用php创建此页面,因此无需在表单中定义您的操作属性,因此您只需从action标记中删除form属性即可。但是您需要处理所选的所有下拉列表答案,因此您可以使用$_POST来获取所有选定的值。

答案 1 :(得分:-2)

<form action="" method="post" action="http://www.naukridigest.com/age-calculator/">

我在action中看到两个form。删除第一个,然后留下:<form method="post" action="http://www.naukridigest.com/age-calculator/">

但是如果没有提供任何进一步的代码(或为此提供任何代码;必须自己跟踪它),我无法帮助解决可能出现的任何其他问题。