SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Problem passing form value
-
Dec 7, 2004, 07:57 #1
- Join Date
- Jul 2004
- Location
- Dublin
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Problem passing form value
Hi, I'm trying to do a simple case of displaying a submitted value but I'm getting a blank output.
This is my form:
<form action="name.php" method ="post">
<input type ="text" size ="45" name="username">
<input type ="submit" value="submit">
</form>
This is the output page:
<?php
echo("your name is $username");
?>
and the output is just:
your name is
What am I doing wrong?
-
Dec 7, 2004, 07:59 #2
- Join Date
- Nov 2004
- Location
- Canada
- Posts
- 373
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$username isnt assigned anything..
try to put this in the code..
$username=$_POST["username"];
This will assign the value submitted from the form ($_POST) to the variable $username
-
Dec 7, 2004, 08:08 #3
- Join Date
- Jul 2004
- Location
- Dublin
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I still get a blank.
Shouldn't I be getting the follwing url?: name.php?username=cosmic_bird
the url I get is just name.php
-
Dec 7, 2004, 08:13 #4
- Join Date
- Jul 2004
- Location
- Dublin
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry tdob, it actually does work now, thanks!
-
Dec 7, 2004, 08:15 #5
When you use the POST method on a form, the URL is whatever is set in the action attribute fo the form, and the named fields on the form are accessible via the $_POST array.
When you use the GET method on the form, the named filelds are append to the action attribute and can thuse be seen. In this case, the variables are accessible via the $_GET array.
For diagnostic purposes, at the top of your name.php file, put the following lines of code
PHP Code:echo 'POST Varaibles <br />';
print_r ($_POST);
echo 'GET Varaibles <br />';
print_r ($_GET);
Hope this helps
-
Dec 7, 2004, 08:18 #6
- Join Date
- Nov 2004
- Location
- Abilene, TX
- Posts
- 92
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The reason your URL is just name.php is because you are posting data, rather than getting data. However, your PHP code is correct. If you are getting blank data, something is wrong on your server end. Try checking your PHP configs. Also, what version of PHP are you running?
Reg
"I don't care how many beers you've had...
Get your chickens out of my lawn!"
-
Dec 7, 2004, 08:21 #7
- Join Date
- Nov 2004
- Location
- Canada
- Posts
- 373
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey,
I am a newbie, but this is generally the type of code I have with forms..
PHP Code:<?php if(isset($_POST["username"])) {
$username=$_POST['username'];
echo 'Your username is '$username''; }
?>
-
Dec 7, 2004, 08:32 #8
- Join Date
- Jul 2004
- Location
- Dublin
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
everything seems to be working ok now, thanks guys!
Bookmarks