Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-08-2005, 04:01 AM   #1
Registered: Oct 2004
Distribution: Mandrake 10.1
Posts: 40

Rep: Reputation: 15
Question Strange PHP problem!!!

Hi everybody,

I have a problem with PHP. I created a very basic html form and I am trying to access the input from a very basic php. For example in the html form I got:

<input type="text" ... ... ... name="email">

And in the php file I have:

print("Email : $email");

But this is not working... I also tried the following...


Always $email seems to be empty...

No syntax errors and other things.

Can you please help?

Old 03-08-2005, 05:09 AM   #2
blue penguin
LQ Newbie
Registered: Dec 2004
Location: New Zealand
Distribution: Debian GNU/Linux (Etch) GRUB, Kubuntu 5.10 GRUB/GNU/Linux
Posts: 27

Rep: Reputation: 15
You have to tell the PHP parsing engine that you want to use the data from the form, if you put this:
$email = $_POST['email'];
before you call $email it should work (assuming your form used the POST method, or if you used the get method it would be:
$email = $_GET['email'];
here is part two (where using data from forms is explained) of an excelent 15 part PHP tutorial by Zend, the PHP company.

Good luck in your PHP progamming :-)
Old 03-08-2005, 06:47 AM   #3
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30

This is a fairly common problem. Until version 4.2.x of PHP, there was a directive called register_globals the default value of which was On. Since 4.2.0 the default value is Off. The difference is how you access variables in sessions, cookies, and forms. If register_globals is set to On, you can do just what you have been trying to do. However, this is insecure, so usually (if the admin is smart) register_globals is set to off. Then you have to have to access the variables like Blue Penguin says to. More information here.

If you have a form with many input items, you can do this:
extract( $_POST ); //if the form has the POST method, otherwise extract( $_GET );
Then you can use the variables as you have trying to. extract() works on any array that has key names for the elements. So if you did this:
$myArray[ 'value1' ] = $something;
$myArray[ 'value2' ] = $somethingElse;
extract( $myArray );
you would then have variables $value1 and $value2.
Old 03-08-2005, 12:07 PM   #4
Registered: Oct 2004
Distribution: Mandrake 10.1
Posts: 40

Original Poster
Rep: Reputation: 15
blue penguin and zaichik,

Thanks... It worked out perfectly. Having people like you around, makes being a newbie easier.

Thanks again...



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
strange value of variable after a php form jeanpba Linux - Software 0 11-15-2005 02:38 AM
strange apache php problem lbharti Linux - Software 3 05-20-2005 10:39 AM
strange, strange alsa problem: sound is grainy/pixellated? fenderman11111 Linux - Software 1 11-01-2004 05:16 PM
Strange PHP problems with Apache trollatm Linux - Software 4 03-11-2003 01:20 AM
strange php problem dsiguy Linux - Software 2 02-18-2003 05:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration