0

I'm trying to access some data I've sent to this page (pincode.php), by using the $_POST[] array. However, it seems the variable isn't set, even though the network tab shows the data got succesfully sent.

Image of successfull POST request

The code I use to get the value from the $_POST[] array (in the pincode.php file):

if (isset($_POST['buy'])) {
$id_buy = $_POST['buy'];
echo $id_buy;
}

The problem is the if-statement doesn't fire, so apperently $_POST['buy'] isn't set.

Does anyone know a possible cause?

UPDATE: As a test, I've created the file: test.php, with the following content: enter image description here

This creates the following result and I still don't get the echo: enter image description here

I am getting the same issue here, am I missing something important?

  • It could be many things. For example, you might have failed to name any of your form inputs "buy": `` – S. Imp Oct 01 '21 at 21:25
  • 3
    @S.Imp If he didn't have the name, why would the Network tab show that a parameter was sent with that name? – Barmar Oct 01 '21 at 21:28
  • Are you submitting a form normally or using AJAX? – Barmar Oct 01 '21 at 21:30
  • Not the cause, just the documentation about what you can expect to work: [PHP: Variables From External Sources (Docs)](https://www.php.net/manual/en/language.variables.external.php). Additionally: Whatever *fire* means, lets assume you're looking for the output of `179`. If `179` is not part of the response there are two reasons: It was never output from the script or it was output but the connection already closed / output buffering may have skipped it. Use `error_log` temporarily, scan the SAPI error log if those messages appear. Alternatively use step debugging (if available). – hakre Oct 01 '21 at 21:32
  • In case of AJAX compare with https://stackoverflow.com/q/5004233/367456 (the basic principles behind that are the same as outlined in the PHP Docs earlier, just additional examples / references for the browser [a.ka. client] part). Network tab should also allow you to inspect response data next to request data. Verify response headers are as expected as well next to the response data itself. – hakre Oct 01 '21 at 21:36
  • I am using AJAX, yes. I will try out your suggestions tommorow! Thank you for responding – Knoquer Bonk Oct 01 '21 at 21:46
  • @Barmar i see no mention of the word 'buy' on that image of the 'network tab'. – S. Imp Oct 02 '21 at 03:11
  • @S.Imp You don't see `buy: 179` on the last line? – Barmar Oct 02 '21 at 04:56
  • I've performed another test, maybe this will clear up the situation a bit more. I've put the result in my original post. Does anyone know why this doesn't work? – Knoquer Bonk Oct 02 '21 at 10:12
  • @barmar the post has since changed, but I saw no appearance of the word 'buy' on the image at all. – S. Imp Oct 02 '21 at 20:33

0 Answers0