Problem with fallowing code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
antosh
Forum Newbie
Posts: 1
Joined: Wed May 12, 2004 2:20 am
Location: India
Contact:

Problem with fallowing code

Post by antosh »

Dear friends

I m working RedHat Linux 9.0 using PHP-4.3-6 and Apache 2-0-47-10 and I getting problem that the form variable can't process php tag the out put fallowing programme is

that is contant of $username variable is empty even though if i enter something in text box


Please Help me :(

<HTML>
<FORM>
Please type your name here:<br>
<INPUT TYPE=TEXT NAME=username><BR><BR>
<INPUT TYPE=SUBMIT VALUE='Enter'>
</FORM>
<BR><BR>

You Typed:
<?php
echo ($username);
?>
</HTML>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try this version:

Code: Select all

<html>
<head>
<body>
<?php
if(!empty($_POST['username'])){
    echo 'You typed : '.$_POST['username'];
}
?>
<form method="post" action="">
Please type your name here:<br>
<input type="text" name="username" value="" size="20" maxlength="20" />
<br /><br />
<input type="submit" name="submit" value="Enter" />
</form>
</body>
</html>
The reason yours doesn't work is you have register_globals Off (and rightly so). So that means if you have a form element named 'username' then once you submit the form you won't get $username, you have to use $_POST['username'] (if the form method is post).

See http://php.net/variables.predefined for more information.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Try $_POST["username"] and have a look at viewtopic.php?t=511
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Gah, you beat me by a couple of seconds, markl999 ;) Yet again!
Post Reply