ConcreteDJ Posted June 25, 2009 Share Posted June 25, 2009 Even the simplest forms do not work for me on Windows XP. Why? No matter what I enter, the input data is not echoed on the screen. Here is the super simple html form, php program, and output I am getting. What am I missing?? <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> <html> <body> Welcome <?php echo $_POST["fname"]; ?>!<br /> You are <?php echo $_POST["age"]; ?> years old. </body> </html> Welcome ! You are years old. Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/ Share on other sites More sharing options...
n1tr0b Posted June 25, 2009 Share Posted June 25, 2009 where's your PHP code?? Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863274 Share on other sites More sharing options...
dzelenika Posted June 25, 2009 Share Posted June 25, 2009 Most possibly your php instalation is not "connected" to web server. Try this script <?php phpinfo(); ?> to be sure php is working. Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863283 Share on other sites More sharing options...
ConcreteDJ Posted June 25, 2009 Author Share Posted June 25, 2009 The original post has ALL the PHP code. Attached is the results of running the phpinfo snippet. Everything seems OK but still cannot echo the variables in the original PHP code. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863391 Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 Make sure they have a value: <?php if(isset($_POST['fname'])) echo $_POST["fname"]; ?> <?php if(isset($_POST['age'])) echo $_POST["age"]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863394 Share on other sites More sharing options...
ConcreteDJ Posted June 25, 2009 Author Share Posted June 25, 2009 Tried the isset snippet in the html, both before and after the </form> but nothing prints so the variables are not being set. Why not? Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863424 Share on other sites More sharing options...
Richard Posted June 25, 2009 Share Posted June 25, 2009 Remember you'll have to filter all input, and escape output. <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" name="submit" value="Submit!" /> </form> </body> </html> <?php if ($_POST['submit']): ?> <html> <body> Welcome <?php if(isset($_POST['fname'])) echo $_POST["fname"]; ?>!<br /> You are <?php if(isset($_POST['age'])) echo $_POST["age"]; ?> years old. </body> </html> <?php endif; ?> Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863433 Share on other sites More sharing options...
ConcreteDJ Posted June 25, 2009 Author Share Posted June 25, 2009 Appreciate your help. I copied/pasted all your code into a text document, saved it as TryAgain.htm. Double-clicked it. In Mozilla, input fields came up, entered data, but still no output. I must be missing something very basic -- but what? Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863448 Share on other sites More sharing options...
Richard Posted June 25, 2009 Share Posted June 25, 2009 Appreciate your help. I copied/pasted all your code into a text document, saved it as TryAgain.htm. Double-clicked it. In Mozilla, input fields came up, entered data, but still no output. I must be missing something very basic -- but what? There is your problem. You need to save your file as .php. Have you got a web server running, and PHP installed? If not have a look at WAMP or XAMPP if you're running a Windows environment. Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863455 Share on other sites More sharing options...
will35010 Posted June 25, 2009 Share Posted June 25, 2009 Appreciate your help. I copied/pasted all your code into a text document, saved it as TryAgain.htm. Double-clicked it. In Mozilla, input fields came up, entered data, but still no output. I must be missing something very basic -- but what? It needs to ba saved as a .php file in your public web folder. Also, best practice on your form action would be action="<?php echo $PHP_SELF; ?>" Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863457 Share on other sites More sharing options...
will35010 Posted June 25, 2009 Share Posted June 25, 2009 Appreciate your help. I copied/pasted all your code into a text document, saved it as TryAgain.htm. Double-clicked it. In Mozilla, input fields came up, entered data, but still no output. I must be missing something very basic -- but what? There is your problem. You need to save your file as .php. Have you got a web server running, and PHP installed? If not have a look at WAMP or XAMPP if you're running a Windows environment. Also, you don't double click the file. You browse to it using IE, Firefox, or etc. You said windows. What are you using for a webserver? XAMPP is what I like on windows. I'd suggest you learn how to setup a proper testing environment and how php code actually runs. Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863458 Share on other sites More sharing options...
Richard Posted June 25, 2009 Share Posted June 25, 2009 Appreciate your help. I copied/pasted all your code into a text document, saved it as TryAgain.htm. Double-clicked it. In Mozilla, input fields came up, entered data, but still no output. I must be missing something very basic -- but what? It needs to ba seved as a .php file in your public web folder. Also, best practice on your form action would be action="<?php echo $PHP_SELF; ?>" will35010, <?php echo $_SERVER['PHP_SELF']; ?> is vulnerable to XSS if used like that. Instead, you could use <?php echo $_SERVER['SCRIPT_NAME']; ?> for your form action (assuming you want your form action to point to itself) Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863459 Share on other sites More sharing options...
PFMaBiSmAd Posted June 25, 2009 Share Posted June 25, 2009 Double-clicked it. And in addition to needing to be a .php file, you must invoke the file using a URL through a web server. You cannot double-click on it as that would just attempt to have the browser open it without going through a web server. @ will35010 - <?php echo $PHP_SELF; ?> was depreciated 7 years ago and has been completely removed in php6, don't suggest code that is obsolete. Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863460 Share on other sites More sharing options...
ConcreteDJ Posted June 25, 2009 Author Share Posted June 25, 2009 I've got Apache 2.2 installed and running. I've tried embedding PHP in web pages or saving the file as .php. I just tried the world's most basic script: <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html> I saved it as .htm, double-clicked and I get: Hello World '; ?> When I save it as .php the screen flashes quickly but I don't get anything at all in the browser. I've tried running scripts just out of folders and also directly from the htdocs folder. I've actually got one XP machine with XAMP running and scripts work on the outside but they behave this way on the inside. On this PC w/XP, I installed Apache 2.2 and PHP individually to see if I could get to the root of the problem. I thought double-clicking would work if the file type association was OK. I am not sure which PHP...exe the .php type should be associated with. I'll try browsing to the files now... Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863464 Share on other sites More sharing options...
ConcreteDJ Posted June 25, 2009 Author Share Posted June 25, 2009 Removed PHP and Apache installations and started over, this time with XAMPP. Same problems. Even tried removing the public IP from this box, using only the IP from the DHCP server, but no go, but I will figure it out one way or the other. Not being very comfortable yet with PHP, I had hoped that I could find something on this forum quickly since I've been working primarily with Visual Studio and VB and figured the pros here might have an idea of what is going on...and yes, I do read the documentation and realize the answers in forums don't happen by accident. I've been self-employed in computers since 1990 and that wasn't be accident either. Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863567 Share on other sites More sharing options...
ConcreteDJ Posted June 25, 2009 Author Share Posted June 25, 2009 The solution I found is html and php files need to live in the htdocs folder. I'll bet many other "newbies" have the same problem but explain it differently. Tell the Newbie: 1. 90% of the PHP manual is reference which is fine if everything is already working 2. Put your html and AND php files in the htdocs folder under XAMPP 3. Use http://localhost/myfile.htm (or .php file) in the address box of their browser -- don't double-click it and expect it to work like other Windows programs 4. Browsing doesn't work from your browser unless the URL starts with http://localhost/ The main reason I started using PHP was I found there are protocol differences between winsock in Visual Studio and the winsock API module loaded in PHP. This created problems validating orders coming from a PayPal server to www.concreteDJ.com using a "listener" and activation server I wrote in Visual Studio. I certainly did appreciate all the fast responses I got at PHP Freaks and learned some things. So to end on a positive note, listen to some tunes on us without wasting screen space while you are coding with our tiny Concrete Minii player. Download it for free at www.concreteDJ.com ... which is good news for you and good news for me because I'm not done with my PHP, yet! Quote Link to comment https://forums.phpfreaks.com/topic/163614-example-form-does-not-show-inputs/#findComment-863747 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.