-3

I've been playing around with PHP but POST & GET seem to never work properly. I've looked all over trying to understand why my html elements cannot be found through their name tags to no avail.

The most common response was to add: if(isset($_POST[...])) but when this is included, the form never goes through as it always returns false.

<html>
<body>
<form action="" method="post">
    <input type="text" placeholder="name here" name="name">
    <input type="submit" name="submit" value="Show name">
</form>
</body>
<?php
if(isset($_POST["submit"])){
    echo $_POST["name"];
}else echo "No name";
?>
</html>

Is this an interpreter issue? I have replicated other people's sample code in which theirs works but I am still faced with the same issues.

Orange Receptacle
  • 1,173
  • 3
  • 19
  • 40

1 Answers1

0

In your php script, use $_POST. This is because the method specified in the html form says post. If you want to use $_GET then change the method attribute to get and not post.
Alternatively you can use $_REQUEST, although it's not security safe.

If all else fails, place your php script at the top just before html

Rotimi
  • 4,783
  • 4
  • 18
  • 27
  • I originally used all POST but out of desperation started changing some to GET to see if it were to make a difference. Using $_POST didn't do anything, however, $_GET was able to display the name. – Orange Receptacle Aug 21 '17 at 05:47
  • Read the last paragraph of my answer – Rotimi Aug 21 '17 at 05:49