View previous topic :: View next topic |
Author |
Message |
darrenfinch -
Joined: 19 Jan 2006 Posts: 6
|
Posted: Thu Jan 19, 2006 2:30 pm Post subject: Newbie help with forms and php |
|
|
Hi all
I have Abywss Web Server install on my Win XP machine and I have recently started learning php (I have installed php 5 and configured the web server to parse correctly and it works fine so I know thats not the problem!)
I have written a very basic form to test (for starters), i.e.
<html>
....
<form action="test1-1.php" method="post">
<textarea name="txt" rows="1" cols="50"></textarea><br />
<input type="submit" value="submit!">
</form>
</body>
and the test1-1.php file contains
<?php
echo "Name is :" $txt;
?>
When I complete the form and hit submit I get undefined variable txt in .......
I am doing soemthing wrong - but I cannot see what!
Can anyone help please! _________________ Red Alert Sir? You know that would mean changing the lightbulb! (RedDwarf) |
|
Back to top |
|
 |
roganty -
Joined: 08 Jun 2004 Posts: 357 Location: Bristol, UK
|
Posted: Thu Jan 19, 2006 2:39 pm Post subject: Re: Newbie help with forms and php |
|
|
darrenfinch wrote: | When I complete the form and hit submit I get undefined variable txt in .......
I am doing soemthing wrong - but I cannot see what!
Can anyone help please! |
Thats because since PHP4 register globals has been turned off by default
you can either search this forum for the answer
or use the following to get the variable:
Code: |
<?php
//There are two ways this can be done
//if you are sending the form using post change all $_GET with $_POST
//you can get and set the variable this way
$txt = ( isset($_GET["txt"]) ) ? $_GET["txt"] : "";
//or this way
$txt = $_GET["txt"];
//now you can do the following
echo "Name is :". $txt; //ps you forgot the "." to concatenate the string...
?>
|
_________________ Anthony R
Roganty | Links-Links.co.uk
Last edited by roganty on Mon Jan 23, 2006 3:28 pm; edited 1 time in total |
|
Back to top |
|
 |
darrenfinch -
Joined: 19 Jan 2006 Posts: 6
|
Posted: Thu Jan 19, 2006 3:11 pm Post subject: |
|
|
Many thanks for that!
btw - I have two computers the test machine is without net so I had to type everything in again! Hence the missing append
Thanks for your help!
(think I will have to find some php 5 reference material now!) _________________ Red Alert Sir? You know that would mean changing the lightbulb! (RedDwarf) |
|
Back to top |
|
 |
kev1952 -
Joined: 08 Sep 2005 Posts: 105 Location: Townsville Australia
|
Posted: Mon Jan 23, 2006 7:29 am Post subject: |
|
|
Using Roganty's code you could also display the result like this:
Code: |
<?php
$txt = $_GET["txt"];
echo "Name is : $txt"; //no need to concatenate the string then ...
?> | There are many ways of doing the same job. This is just the way I do it and it always works fine. _________________ Cheers.... Kev
Kev's Place - http://www.kevsplace.com
Powered by Abyss X1. |
|
Back to top |
|
 |
roganty -
Joined: 08 Jun 2004 Posts: 357 Location: Bristol, UK
|
Posted: Mon Jan 23, 2006 3:35 pm Post subject: |
|
|
kev1952 wrote: | Using Roganty's code you could also display the result like this:
Code: |
<?php
$txt = $_GET["txt"];
echo "Name is : $txt"; //no need to concatenate the string then ...
?> |
|
True, I could of done it like that, and that is the way that I mainly work.
The whole point of my post was to show how to get the variable from either a get or post environment using the code that darrenfinch had provided
kev1952 wrote: | There are many ways of doing the same job. This is just the way I do it and it always works fine. |
Just a note,
There is more than nine ways to skin a cat!
~No Flame Intended~ _________________ Anthony R
Roganty | Links-Links.co.uk |
|
Back to top |
|
 |
|