bhazzard Posted January 20, 2006 Share Posted January 20, 2006 I want PHP to accept the form variable userName and print it... but it want. Globals are set to off, but I've done a work around that should work.HTML File:<html><head><title>What’s your name?</title></head><body><h1>What’s your name?</h1><h3>Writing a form for user input</h3><form method="post" action="hiUser.php">Please type your name:<input type="text" name="userName" value=""><br><input type="submit"></form></body></html>PHP File:<html><head><title>hiUser.php</title></head><body><h1>Hi User</h1><h3>PHP program that receives a value from "whatsName"</h3> <?php /*gets the variables from the form on whatsName.html and outputs text*/ //retrieves the userName element from the form $userName = $_REQUEST[“userName”]; //outputs text and html echo "<h3>Hi there, $userName!</h3>"; ?></body></html>Thanks in advance for your help. I am a newbie and I am trying to learn. Link to comment Share on other sites More sharing options...
bd1e0d0 Posted January 24, 2006 Share Posted January 24, 2006 It's staring you right in the face! Your form was set to POST, and your variable was set to $_REQUEST. Use $_POST to get the variable. But if you wanted to use $_REQUEST, set the form to GET. Here (fixed up some of the XHTML for ya, too, also got rid of the comments beacuse I knew you put them there for this board):HTML File: <html> <head> <title>What’s your name?</title> </head> <body> <h1>What’s your name?</h1> <h3>Writing a form for user input</h3> <form method="post" action="/hiUser.php"> Please type your name: <input type="text" name="userName" value="" /><br /> <input type="submit" /> </form> </body></html> PHP File: <html> <head> <title>hiUser.php</title> </head> <body> <h1>Hi User</h1> <h3>PHP program that receives a value from "whatsName"</h3> <?php $userName=$_POST['userName']; echo("<h3>Hi there, ".$userName."!</h3>"); ?> </body></html> Link to comment Share on other sites More sharing options...
bhazzard Posted January 24, 2006 Author Share Posted January 24, 2006 Hey thanks... I am new to all of this and I am learning from a published book... strange thing is, that the syntax that they gave me was wrong. So I am going to have to find a new book that knows what it is talking about. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now