0

I am trying to get the variable from my form but it gives me nothing, i also did var_dump of post and it shows me that the array is 0 so the form isn't sending data. I tried so many things but i think i have some kind of bug or my installtion wasn't good. The softwares i am currently using is WampServer, PHP version 7.0.10 and PHPStorm on windows 10.

<html>
<head lang="en">
<meta charset="UTF-8">
</head>
   <body>

<!-- language: PHP -->   
<?php
if(isset($_POST['age'])) {
    $varKapitaal = $_POST['age'];
    echo $varKapitaal;
}
?>

    <h1>Fill in the form</h1>

    <form method="POST" action="">
        <p>age:</p>
        <input type="text" name="age">
        <input type="submit" name="submit">
    </form>
</body>
</html>
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
  • 2
    It works fine (the code, I just tested it), so you have something else wrong, perhaps your install. – junkfoodjunkie Mar 04 '17 at 19:34
  • I removed the `phpstorm` tag, since it doesn't have anything to do with your question or issue. – M. Eriksson Mar 04 '17 at 19:47
  • make a new file and try to just hello world. if it works that means your php is working fine or you can go with phpinfo() to see details. if php works fine try reinstalling wamp. – Resheil Agarwal Mar 04 '17 at 19:52

1 Answers1

0

No, it's not a bug. You just need specified the action url, where the post must seend data. Example

I use the Xampp, and create the directory&file C:\xampp\htdocs\try\index.php

<html>
   <head lang="en">
   <meta charset="UTF-8">
</head>
<body>

 <!-- language: PHP -->
 <?php
     if(isset($_POST['age'])) {
     echo $_POST['age'];
     }
  ?>

  <h1>Fill in the form</h1>

  <form method="POST" action="http://localhost/try/">
      <p>age:</p>
      <input type="text" name="age">
      <input type="submit" name="submit">
  </form>

Just change action from empty to URL of that php file, like in my example action="http://localhost/try/"

U. Andrian
  • 26
  • 2
  • An empty action attribute will post to itself and since the OP says that he/she sees the result of `var_dump()` (even though it's empty), it's safe to say that the post _does_ go to the correct page. – M. Eriksson Mar 04 '17 at 23:06
  • @U. Andrian I tried what you said and it's still doesn't show the variables – usman mughal Mar 06 '17 at 14:30
  • I solved it by putting my project in C:/wamp(64)/www/ thanks for the replies – usman mughal Mar 06 '17 at 14:42