0

I have two PHP scripts. One posts a message "Hello" while the other receives it. Currently, the second PHP script receives a _POST['message'] but the contents of that message is empty!

Script One:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
 'message' => 'Hello'
));
$result = curl_exec($ch);
if($result) {
echo("Successful post");
}
curl_close($ch);

Script Two:

if($_POST['message']) {
  echo("received post message");
  echo ("message:" . $POST['message']);

Currently script Two prints "received post messagemessage:"

I'm completely flummoxed - from looking at this post, it seems my syntax is correct....

Community
  • 1
  • 1
AllieCat
  • 3,890
  • 10
  • 31
  • 45
  • Have a look at this http://stackoverflow.com/questions/17618160/php-curl-not-storing-json-encoded-echoed-data I had a similar issue – Liam Sorsby Aug 11 '13 at 13:26
  • 1
    Hard to spot typo: `$POST` should be `$_POST`. This means you need to turn on `display_errors` and crank up `error_reporting` because you would have seen a `Notice: undefined variable $POST`. Always in development, do `error_reporting(E_ALL); ini_set('display_errors', 1);` – Michael Berkowski Aug 11 '13 at 13:28
  • Also, when debugging I recommend working backward. If you didn't get what you expected from `$_POST['message']`, broaden it a little to the full array and check `print_r($_POST);` there, you would have seen your expected value. – Michael Berkowski Aug 11 '13 at 13:30
  • This question appears to be off-topic because it is related to a minor typographical error – Michael Berkowski Aug 11 '13 at 13:31

1 Answers1

1

Script two has wrong syntax, it must be $_POST.

if($_POST['message']) {
  echo("received post message");
  echo ("message:" . $_POST['message']);
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126