2

The post superglobal variable is empty after form submission; however, get works!

Here is the code:

index.php

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Simple Form</title>
</head>
<body>
<fieldset>
    <form  action="print.php" method="POST" >
        first name:<input type="text" name="Fname"><br>
        last name:<input type="text" name="Lname"><br>
        <input type="submit" name="submit" value="submit">
    </form>
</fieldset>

</body>
</html>

print.php

<?php
echo $_POST['Fname'];
echo $_POST['Lname'];
?>

same code works fine on my PC and print.php prints something but here on my Macbook $_post is always null after submitting the form.

I use IntelliJ IDEA as my IDE with Php plugin.

I use php 7

2
  • 1
    so what is your question? Commented Feb 5, 2016 at 12:31
  • @hmtareque I can't use form's data on server side because $_POST is always null it is not populated by form's data.
    – Sina
    Commented Feb 5, 2016 at 12:50

1 Answer 1

3

IntelliJ is not mapped to the MAMP server. That's why php is interpreted but POST does not work. In order to map MAMP to IntelliJ use this guide which works for IntelliJ ultimate edition and PhpStorm.

4
  • I don't understand why I need a MAMP server for php to receive POST data. I have a local copy of php installed (including php-cgi), and I configured IntelliJ to use it under Settings -> Languages & Frameworks -> PHP. When I click the browser icon while editing a php page, the page appears in the web browser. The only problem is that $_POST is empty. This doesn't sound like something I need MAMP for. (In fact, when I last worked with PHP a year ago, a similar configuration worked --- although it was IntelliJ 13 and PHP 5.6.)
    – Zack
    Commented May 2, 2016 at 18:35
  • @Zack That's exactly what my problem was. According to this guide under the "Integrating the Apache server" title you will find out that IntelliJ needs to deploy your project to a web server and MAMP is a local web server that serves your web pages. IntelliJ is not a web server itself. It only uses plugins to deploy projects to web servers. The reason that $_POST is empty is that there is no one to serve as a server until you add MAMP to do that for you.
    – Sina
    Commented May 7, 2016 at 15:07
  • If there is no one to serve as a server, then why are the the other aspects of the php page working? (I'm not being argumentative, I'm just curious how everything works.)
    – Zack
    Commented May 9, 2016 at 14:10
  • @Zack Because IntelliJ can interpret php alone even $_POST is interpreted but it does not work until it is served by a server because $_POST is a request method supported by the HTTP protocol and all requests must be handled by a server. You can find more about HTTP requests here and about $_POST here.
    – Sina
    Commented May 13, 2016 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.