Forum Moderators: coopster

Message Too Old, No Replies

Problem getting form data

newbie php problem :)

         

Reflection

11:48 pm on Dec 11, 2003 (gmt 0)

10+ Year Member



Ok, this is bugging me because I know its something simple. I set up php on my local machine using the install package from firepages.com, end everything is working fine, Ive written my first php scripts and they all work except one...

Im having trouble with getting information from a form. I was following some little tutorial just to get my handle on things and I did everything exactly like the tutorial except it doesnt work.

Here is my simple little html form:

<form action="test.php" method=post>
<fieldset><legend>Form</legend>
<label for="name">Name:</label><input type="text" size="15" id="name" name="name"><br><br>
<label for="text">Text:</label><input type="text" size="15" id="text" name="text"><br><br>
<input type="submit" name="submit" value="Click Me">
</fieldset>
</form>

Now I know my form works because I switched it to 'get' and I can see the values in the query string and retrieve them with a little javascript function, but when it comes to php I cant get the values.

Here is the php nearly identical to the tutorial...

Hi <?php print $name;?><br><br>
You entered: <?php print $text;?>

According to the tutorial all you have to do to get data from a form field is call the variable of the form field, $name. Am I wrong in this or missing a step in between?

Can someone point out my stupid mistake or tell me what I may have done wrong? :)

Thanks

NickCoons

11:51 pm on Dec 11, 2003 (gmt 0)

10+ Year Member



Look at enabling register globals in your php.ini file, or using the globals $_GET or $_POST. This is a very common issue.

Reflection

12:08 am on Dec 12, 2003 (gmt 0)

10+ Year Member



Thanks Nick that took care of it.

ergophobe

3:37 pm on Dec 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



By preference, use $_GET['name'], $_POST['name'], etc because if you are on a shared server, it is common that register globals will be off and you won't be able to change that.
Tom