gigyani Posted January 17, 2015 Share Posted January 17, 2015 Hello. i am totally new to php and just started to learn now. i just dont understand why the following code is not printing the username that i enter on the page. Please note that the code itself is saved with the name "basicForm.php". Thanks. <html> <head> <title> Basic Form </title> <?php $username = $_POST['username']; print ($username); ?> </head> <body> <form name"form1" method="POST" action="basicForm.php"> <input type="text" value="username" name="username"> <input type="submit" name="submit" value="submit"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
dde Posted January 17, 2015 Share Posted January 17, 2015 (edited) Where is this basicForm.php located? Are you running it on a server supporting php?The code itself is working. Note though that there is a typo <form name"form1" method="POST" action="basicForm.php"> This however is not the cause of your problem. Edited January 17, 2015 by dde Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 17, 2015 Share Posted January 17, 2015 Try this: <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); if (isset($_POST{'username'])) { $username = $_POST['username']; echo "You entered: $username"; exit(); } ?> <html> <head> <title> Basic Form </title> </head> <body> <form name="form1" method="POST" action="basicForm.php"> <input type="text" name="username" value="username"> <input type="submit" name="submit" value="Submit"> </form> </body> </html> - Fixed the name= error- Organized your code to keep html separate from your php - added error checking Quote Link to comment Share on other sites More sharing options...
gigyani Posted January 18, 2015 Author Share Posted January 18, 2015 Where is this basicForm.php located? Are you running it on a server supporting php? The code itself is working. Note though that there is a typo <form name"form1" method="POST" action="basicForm.php"> This however is not the cause of your problem. I am using a wamp local server and the file is located in the www directory without any subfolders. Try this: <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); if (isset($_POST{'username'])) { $username = $_POST['username']; echo "You entered: $username"; exit(); } ?> <html> <head> <title> Basic Form </title> </head> <body> <form name="form1" method="POST" action="basicForm.php"> <input type="text" name="username" value="username"> <input type="submit" name="submit" value="Submit"> </form> </body> </html> - Fixed the name= error- Organized your code to keep html separate from your php - added error checking Thanks alot. let me try this. meanwhile since i am totally a newbie so can you kindly explain whats happeneing here. will it display an error incase it couldnt located the file or the form field name? thanks a lot. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 18, 2015 Share Posted January 18, 2015 I will let you learn from experience. That means do as I said: Try It! And then look up the things you don't know in the manual - you know, the official PHP online manual that everyone has access to. Look that up too! You'll never learn anything if you don't experiment. Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted January 18, 2015 Solution Share Posted January 18, 2015 (edited) I am using a wamp local server and the file is located in the www directory without any subfolders. Make sure you are accessing http://localhost to run your .php files. Loading them directly into your web browser (the address bar starts with file://) will not work. Edited January 18, 2015 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
gigyani Posted January 18, 2015 Author Share Posted January 18, 2015 Make sure you are accessing http://localhost to run your .php files. Loading them directly into your web browser (the address bar starts with file://) will not work. Thank a bunch Ch0cu3r... you solved my problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.