-1

SOLVED

I am trying to submit the value of $data['saleId'] to the info.php page.

       echo "<form action='info.php' method='post'>
       <input type='hidden' name='saleId' value='$data['saleId']'>
       <input type='submit' value='View Info'>
       </form>";

gives

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

user2892730
  • 31
  • 1
  • 7

1 Answers1

1

The string formed is incorrect.

Using string concatenation:

echo "<form action='info.php' method='post'>
       <input type='hidden' name='saleId' value=\'".$data['saleId']."\'>
       <input type='submit' value='View Info'>
       </form>";

Using HereDoc:

echo <<<EOD
 <form action='info.php' method='post'>
       <input type='hidden' name='saleId' value='{$data['saleId']}'>
       <input type='submit' value='View Info'>
 </form>
EOD;

Note EOD; should always be at the start of the line.

Please refer: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Ketan Yekale
  • 2,108
  • 3
  • 26
  • 33