Jump to content

Basic Question


bhazzard

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...