1

I am currently having an issue with having my POST requests display what is required, that is, echo the user input. I am using PhpStorm as my IDE and XAMPP, from the installer for Windows, as my stack.

The user submission form looks as follows, it is a .php file.

<form method="post" action="matches-submit.php">
            <fieldset>
                <legend>Returning User:</legend>
                <ul>
                    <li><label><strong>Name:</strong></label>
                        <input id="name" name="name" type="text" size="16">
                    </li>
                    <li>
                        <input id="submit" name="submit" type="submit" value="Sign Up">
                    </li>

                </ul>
            </fieldset>

        </form>

The form that is supposed to handle this submission is as follows:

<html>
    <body>
    Welcome
        <?php
            echo $_POST["name"];
        ?>
    </body>
</html>

However, I am getting an undefined index error. The same issue occurs on my mac where I use the MAMP stack instead. $_GET works fine, however, per good practice you do not want to use GET when handling forms.

How can I fix it so that it will output "Welcome $UserInputHere"?

walther
  • 13,466
  • 5
  • 41
  • 67
SomeStudent
  • 2,856
  • 1
  • 22
  • 36
  • Using this exact script, it worked for me. Are the headers being sent? –  Oct 23 '16 at 02:14
  • Try `"
    ",print_r($_POST),"
    ";` - That'll display the `POST` array and all its contents, you'll start to get an idea where you're going wrong, if there's no content in the array then it's a problem with the sending operation. Make sure you're not just opening the page without clicking submit on the form. :)
    – Jack Hales Oct 23 '16 at 02:22
  • Doing further research it seems as though phpstorms built in web server has issues with post since get works. Thus, as a follow up, I am wondering if any of you know how to make phpstorm use your own apache server. I downloaded the MAMP stack for my mac, and of course XAMPP for windows. – SomeStudent Oct 23 '16 at 02:56
  • also result of that command is: Array ( ). So POST seems to send nothing. – SomeStudent Oct 23 '16 at 02:58
  • http://stackoverflow.com/a/34787827/783119 – LazyOne Oct 23 '16 at 10:11
  • You can avoid the undefined index if you add an isset($_POST) –  Oct 23 '16 at 16:15
  • @LazyOne problem is that I am uncertain how to correctly configure the in place server – SomeStudent Oct 23 '16 at 16:48
  • 2
    Be very careful... use `htmlspecialchars()` around any arbitrary data used in the context of HTML, (such as your `$_POST['name']`). Otherwise, you'll risk opening yourself up to injection of code in your page. – Brad Oct 23 '16 at 22:52
  • Please append the sourecode of `matches-submit.php` (use pastebin if it is very long). – Daniel W. Nov 03 '16 at 09:48

2 Answers2

0

So I found a solution. This of course is on my Windows machine, but I suppose a similar thing applies to Macs. Go to the xampp folder, find the httpdocs folder, and do your work there.

After that, turn on the server and you should be able to access it normally via localhost. Meaning, you can still use phpstorm as your ide, but bypass its build in server which is having issues with post.

SomeStudent
  • 2,856
  • 1
  • 22
  • 36
0

That's not the solution. I use PHPStorm and XAMPP together with the webroot folder located in the default PHPStorm project location (all it takes is the modification of the VirtualHost entry, DocumentRoot) and my request responses work fine.

It's probably a trivial misconfiguration most likely in your previous .htaccess

Edit: To set up your virtual host, follow this:

  • Enter C:\xampp\apache\conf\extra, edit http-vhosts.conf, add this:

<VirtualHost *:80> ServerName localhost DocumentRoot C:\Users\YOUR_PHPSTORM_PROJECT_FOLDER </VirtualHost>

  • Edit C:\system32\drivers\etc\hosts if you chose a server name other than localhost, add the following entry: 127.0.0.1 arbitraryservername

  • Restart XAMPP

If you are getting HTTP 403, you might need to add Require all granted (or Allow from all in older versions of apache) for the webserver root directory. That's all.

Rápli András
  • 3,869
  • 1
  • 35
  • 55
  • Maybe, idk, I am a total novice and our professor has shown us 0 things as far as set up is concerned. I tried making phpstorm go through the server and it fails all the time. Tried youtube vids, etc. and nothing worked except for that. If you can tell me how to do it, that would be great. – SomeStudent Oct 24 '16 at 01:34
  • added some info about how to set up your vhost – Rápli András Nov 03 '16 at 09:35