-1

I am creating a simple form with HTML and PHP.I put this code in index.html:

 <form action="formdata.php" method="post">
  <h3 class="h3">First Name:</h3>
  <input type="text" name="fname"></input>
  <h3 class="h3">Last Name:</h3>
  <input type="text" name="lname"></input>
  <br>

  Male
  <input type="radio" name="sex" value="Male"></input>
  Female
  <input type="radio" name="sex" value="Female"></input><br>

  <input type="Submit" value="submit"></input><br>
 </form>

And here is my PHP code:

<html>
 <head>
  <title>PHP script</title>
 </head>
 <body>
   First Name: <?php echo $_POST["fname"]; ?><br>
   Last Name: <?php echo $_POST["lname"]; ?>
 </body>
</html>

But the output in php is not showing names.It just showing

First Name:
Last Name:

What should i do?

Ans
  • 153
  • 1
  • 13
  • Is the `PHP` code in `formdata.php` ? Additionally, what does `print_r($_POST);` show? Presumably you are sending the form data to a wrong location as it looks ok. – Jan Jan 05 '16 at 16:47
  • 4
    Question is, how are you accessing this? as `http://localhost/file.xxx` or as `c://file.xxx`? Those are 2 different animals altogether and make sure PHP is installed and running. – Funk Forty Niner Jan 05 '16 at 16:51
  • I'm tempted to close this question with ^ given the additional answer. Edit: I have. – Funk Forty Niner Jan 05 '16 at 16:58

2 Answers2

0

try this, it's work for me in Core PHP

<?php $_POST["fname"]; ?>
Kashif Latif
  • 645
  • 2
  • 13
  • 27
-1

Just ran this code verbatim on my WAMP server. Everything worked properly. Are you sure you are running your .html file from inside your web server directory (localhost / 127.0.0.1) If you are not, PHP will not have any of the POST data handed to it.

Haymaker
  • 119
  • 13