[Solved] POST function not working with my php code however in the same function GET is working [duplicate]


If you want to access the variable via the $_POST array, you have to specify post as the method in your form (or in whatever mechanism you’re using to hit the file, like an AJAX request or something, you’d need to specify “post” accordingly):

<form method="post" action="your-file-or-route">

If you don’t want to worry about that, or you don’t care whether it got to you via POST or GET, PHP does offer a $_REQUEST array, which combines the two (and $_COOKIE). See here: http://php.net/manual/en/reserved.variables.request.php

(You may also want to check that the value exists in whatever array you use before you try to display it, with isset() [1] or empty() [2] or array_key_exists() [3].)

solved POST function not working with my php code however in the same function GET is working [duplicate]