Page 1 of 1

PHP noob - Need help with HTML/PHP form that posts.

Posted: Wed Nov 10, 2004 7:20 pm
by Salcom
I'm trying to get a simple form on several pages that anyone can fill and post to that same page. sort of an opinion feedback that anyone can read when they see the page.

I've got the HTML form perfect, but the PHP file is wrong i think, cause when i test the form, it echoes to the PHP file and doesn't post, just has the names of the form boxes blank.

can anyone help??

here's the PHP code i tried

Code: Select all

<html>
<head>
<title> Angel Form</title>
</head>
<body>
<?php
echo "<p>Name: <b>$_post&#1111;name]</b></p>";
echo "<p>Email:<br>$_post&#1111;email]</b></p>";
echo "<p>Website:<br>$_post&#1111;site]</b></p>";
echo "<p>Your Thoughts:<br>$_post&#1111;feed]</b></p>";
?>
</body>
</html>
[/php_man]

Posted: Wed Nov 10, 2004 8:00 pm
by rehfeld
heres how ti works

Code: Select all

&lt;?php

echo $_POST&#1111;'firstname'];

?&gt;

&lt;form method="post" action="demo.php"&gt;
&lt;input type="text" name="firstname" value="&lt;?php echo $_POST&#1111;'firstname']; ?&gt;"&gt;
&lt;input type="submit"&gt;
&lt;/form&gt;
does that help?

Posted: Wed Nov 10, 2004 8:12 pm
by josh
If anyone is going to be able to post to a page make sure you run htmlspecialchars() before you echo it!

http://us2.php.net/htmlspecialchars

Posted: Wed Nov 10, 2004 8:47 pm
by Salcom
is that the HTML or PHP code? cause i tried that and now when i try the form on the page, it just goes to the PHP file with a small textbox and a submit query button :(

Posted: Wed Nov 10, 2004 8:49 pm
by rehfeld
Salcom wrote:is that the HTML or PHP code? cause i tried that and now when i try the form on the page, it just goes to the PHP file with a small textbox and a submit query button :(
try using it, you will see how it works

Posted: Wed Nov 10, 2004 8:52 pm
by josh
It is php and html code... When the page first loads it shoud display the box and button, fill in some info and press the button. It should echo the variable at the top of the page for you and the variable should remain in the textbox so you can edit it.

The reason you want to run htmlspecialchars is because a user could put the following in the textbox which would screw some stuff up.

Code: Select all

">
<input type="submit">
</form><BR><BR><h1>This will screw up your script!</h1>

Posted: Wed Nov 10, 2004 8:56 pm
by Salcom
I did, i think i'm a bit lost. Does that code go on the HTML page? or the PHP file?

Posted: Wed Nov 10, 2004 9:03 pm
by rehfeld
its not meant to solve your problem, its to try and show you how it works(so that you can understand it)

save the entire thing to a file named demo.php(you can mix html and php in the same php file)

enter some text into the text field, hit submit, and see what happens. look at the html source output from the script too