popoval Posted April 3, 2007 Share Posted April 3, 2007 Hi. I have just started learing PHP and have run into trouble. I am trying to create a form. on the first page (testform.php) i have this code: <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> <br> <form action="/processForm.php" method="get"> Enter youre name <input type="text" name="userName"><br> <input type="submit" name="submit"> </form></body> </html> If I enter my Name "Alex" an click Submit it openes the next page: ProcessForm.php?user_name=alex&submit=Submit+Query On that page I have this code: <html> <head> <title>PHP Test</title> </head> <body> <?php print "hi $userName<br>"; ?></body> </html> According to my book the page would now display: Hi alex But it does not work. What am I doing wrong? Thanks Alex Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/ Share on other sites More sharing options...
only one Posted April 3, 2007 Share Posted April 3, 2007 try using an echo "$userName"; or print ("$userName"); o yea, the form action should probobally be post, or you could put session_start(); at the top of the page (in php tages) Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220450 Share on other sites More sharing options...
popoval Posted April 3, 2007 Author Share Posted April 3, 2007 try using an echo "$userName"; or print ("$userName"); o yea, the form action should probobally be post, or you could put session_start(); at the top of the page (in php tages) I did try with both echo "$userName"; and print ("$userName"); but did not work. I must say I did not understand wat you ment with session_start(); where to you want me to put it? as first line after <?php ? What should be between () ? Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220463 Share on other sites More sharing options...
Daniel0 Posted April 3, 2007 Share Posted April 3, 2007 It needs to be $_GET['userName'] unless you have register_globals on (which you shouldn't). Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220467 Share on other sites More sharing options...
mmarif4u Posted April 3, 2007 Share Posted April 3, 2007 Simply try this <?php echo phpinfo(); ?> Or try ur form in this way. <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> <form action="processForm.php" method="post"> Enter youre name <input type="text" name="userName"> <input type="submit" name="submit"> </form> </body> </html> processForm.php code <?php If(isset($_POST['submit'])) { $username=$_POST['userName']; echo $username; } ?> Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220470 Share on other sites More sharing options...
only one Posted April 3, 2007 Share Posted April 3, 2007 first page: <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> <form action="/processForm.php" method="post"> Enter youre name <input type="text" name="userName"> <input type="submit" name="submit"> </form></body> </html> second page: <html> <head> <title>PHP Test</title> </head> <body> <?php $userName = $_GET['userName']; print "hi $userName"; ?></body> </html> or firstpage: <?php session_start(); ?> <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> <form action="/processForm.php" method="get"> Enter youre name <input type="text" name="userName"> <input type="submit" name="submit"> </form></body> </html> second page: <?php session_start(); ?> <html> <head> <title>PHP Test</title> </head> <body> <?php $userName = $_GET['userName']; print "hi $userName"; ?></body> </html> Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220472 Share on other sites More sharing options...
neel_basu Posted April 3, 2007 Share Posted April 3, 2007 Just replace $userName With $_GET['userName'] if you use GET if you use POST use $_POST['userName'] Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220476 Share on other sites More sharing options...
popoval Posted April 3, 2007 Author Share Posted April 3, 2007 Thanks all.. this solved my problem. I think maybe my book is to old or something but at least it works now. Thanks again =) Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220483 Share on other sites More sharing options...
neel_basu Posted April 3, 2007 Share Posted April 3, 2007 Your book is of PHP4 And you are using PHP5 Link to comment https://forums.phpfreaks.com/topic/45402-solved-need-help-with-a-form/#findComment-220485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.