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....

4
  • Have a look at this stackoverflow.com/questions/17618160/… I had a similar issue Commented Aug 11, 2013 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); Commented Aug 11, 2013 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. Commented Aug 11, 2013 at 13:30
  • This question appears to be off-topic because it is related to a minor typographical error Commented Aug 11, 2013 at 13:31

1 Answer 1

1

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

if($_POST['message']) {
  echo("received post message");
  echo ("message:" . $_POST['message']);
Sign up to request clarification or add additional context in comments.

1 Comment

@AllieCat, Welcome . Don't be ^_^

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.