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> Link to comment https://forums.phpfreaks.com/topic/294017-php-print-help/ Share on other sites More sharing options...
dde Posted January 17, 2015 Share Posted January 17, 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. Link to comment https://forums.phpfreaks.com/topic/294017-php-print-help/#findComment-1503273 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 Link to comment https://forums.phpfreaks.com/topic/294017-php-print-help/#findComment-1503274 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. Link to comment https://forums.phpfreaks.com/topic/294017-php-print-help/#findComment-1503314 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. Link to comment https://forums.phpfreaks.com/topic/294017-php-print-help/#findComment-1503318 Share on other sites More sharing options...
Ch0cu3r Posted January 18, 2015 Share Posted January 18, 2015 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. Link to comment https://forums.phpfreaks.com/topic/294017-php-print-help/#findComment-1503323 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. Link to comment https://forums.phpfreaks.com/topic/294017-php-print-help/#findComment-1503329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.