0

I'm trying to pass on some hidden fields in a form from one page to another:

<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 contains:

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

I get this error on when I click submit and am redirected to secondPage.php:

Fatal error: Array callback has to contain indices 0 and 1 in C:\xampp\htdocs\blah\secondPage.php on line 2
1
  • Killing Curves. Arrays in PHP are accessed with [] not () $_POST("to"); should be $_POST["to"]; Commented Nov 6, 2015 at 20:31

1 Answer 1

21

PHP uses square brackets rather than parentheses for accessing arrays:

<?php

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

?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.