PHP form won't submit to $_POST


Noob alert! I am doing Kevin Skoglund's PHP Essentials course on Ch. 11 is an example to illustrate superglobals. He is using php 5.6 and my WAMP is setup for php 7.0.1. I can't get this simple form to post to the superglobal and I have no idea why.

       $username = $_POST["username"];
       $password = $_POST["password"];
        $message = "Logging in {$username}";
    } else{
        $message= "The form was not submitted";

<html lang="en">
    <title>Hello World</title>
    <?php echo $message;?>
    <form method="post" action="">
        <label for="username">Username: </label>
            <input type="text" name="username" id="username" value=""/>
            <br />
        <label for="password">Password:</label>
            <input type="password" name="password" id="password" value=""/> <br />
        <input type="submit" name="submit" value="Submit"/>

The output is always null regardless of what is typed into the two fields. Its running from localhost directory, WAMP is live. What could cause such a simple error?




Firstly thanks to everyone who tried to help me. It wasn't the code but in the end the error seems to originate in PHPstorm. When running the php file by having the IDE initiate it there seems to be a port number being added in the localhost address.http://localhost:63342/www/Helloworld.php?_ijt=6jrieg9npqffa11j0l2k3bv05h

This is causing the post values to get lost when running the form, and the superglobal comes back empty as a result.

When I initiate localhost directly from WAMP menu and type in the url for the file e.g.http://localhost/Helloworld.php, then the code runs as intended. I still have to sort out how to get PHPstorm to run the php files into the correct localhost instance but for now there's a workaround.

People are also looking for solutions to the problem: display exact array elements using php


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.