PHP user input through HTML tag -
i started learning php, video tutorials on youtube , stuff, , can't figure out why following doesn't work.
i have 2 files, 1 index.php
, other secondpage.php
the contents of index.php
<html> <head> <title>hello world</title> </head> <body> <form action="secondpage.php"> <input name="name" type="text"> <input type="submit"> </form> </body> </html>
and contents of secondpage.php
<html> <head> <title>second page</title> </head> <body> <?php echo $name; ?> </body> </html>
i expect clicking submit on first page output out whatever text typed in in input box, blank page. why?
you need value first. also, need correct method in form tag.
<form>
defaults if method isn't defined, therefore use method="post"
.
html:
<form action="secondpage.php" method="post">
php:
<?php $name = $_post['name']; echo $name; ?>
that it.
edit: didn't mean paoch answer. in time took write it, 4 comments came in saying same thing.
Comments
Post a Comment