Jump to content

Example Form Does Not Show Inputs


ConcreteDJ

Recommended Posts

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.

Link to comment
Share on other sites

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; ?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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; ?>"

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.