Newbie help with forms and php

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
darrenfinch
-


Joined: 19 Jan 2006
Posts: 6

PostPosted: Thu Jan 19, 2006 2:30 pm    Post subject: Newbie help with forms and php Reply with quote

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 View user's profile Send private message
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Thu Jan 19, 2006 2:39 pm    Post subject: Re: Newbie help with forms and php Reply with quote

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 View user's profile Send private message Visit poster's website
darrenfinch
-


Joined: 19 Jan 2006
Posts: 6

PostPosted: Thu Jan 19, 2006 3:11 pm    Post subject: Reply with quote

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 View user's profile Send private message
kev1952
-


Joined: 08 Sep 2005
Posts: 105
Location: Townsville Australia

PostPosted: Mon Jan 23, 2006 7:29 am    Post subject: Reply with quote

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 View user's profile Send private message Send e-mail Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Mon Jan 23, 2006 3:35 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group