PHP:隐藏字段的POST数据错误

时间:2013-08-30 12:03:06

标签: php post

我正在尝试将表单中的某些隐藏字段从一个页面传递到另一个页面:

<form action=\"secondPage.php\" method=\"post\">
   <input name=\"from\" type=\"hidden\" value=\"$fday/$fmonth/$fyear\">
   <input name=\"to\" type=\"hidden\" value=\"$tday/$tmonth/$tyear\">
   <input type=\"submit\">
</form>

secondPage.php包含:

<?php
   $fdate = $_POST("from");
   $tdate = $_POST("to");
   echo "$fdate --- $tdate";
?>

当我点击提交并重定向到secondPage.php时,我收到此错误:

Fatal error: Array callback has to contain indices 0 and 1 in C:\xampp\htdocs\blah\secondPage.php on line 2

1 个答案:

答案 0 :(得分:22)

PHP使用方括号而不是括号来访问数组:

<?php

    $fdate = $_POST["from"];
    $tdate = $_POST["to"];
    echo "$fdate --- $tdate";

?>