0

I am trying to submit a form by post method on itself. but every time the form submits and page is refreshed. it doesn't show values.

<?php echo $_POST['fname']; ?>
<form method="POST" action='#.php'>
<input type="text" name="fname" id="fname" />
<button id="check" name="check" type="submit">GO</button>
</form>

What's the point, i am missing?

3 Answers3

1

Try this :

<?php echo $_POST['fname']; ?>
<form method="POST" action=""> <!-- not single quote -->
<input type="text" name="fname" id="fname" />
<input type="submit" name="value" >
</form>
FullStack
  • 198
  • 7
  • 16
KavitaP
  • 61
  • 5
0

Try this...

<?php 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

echo "<pre>";
print_r($_POST);

} ?>

<form name="test" action="" method="post"><input type="text" name="firstName" /><input type="submit" name="Submit" /></form>
-1

I would recommend to write more cleaner way. like this:

<?php 
if(isset($_POST['fname']) && !empty($_POST['fname']) ){
 echo $_POST['fname'];
}
?>
<form method="POST" action=""> <!-- not single quote -->
<input type="text" name="fname" id="fname" />
<input type="submit" name="value" >
</form>
Ruhul Amin
  • 1,751
  • 15
  • 18