Page 1 of 1

Problem with fallowing code

Posted: Wed May 12, 2004 2:20 am
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>

Posted: Wed May 12, 2004 3:02 am
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.

Posted: Wed May 12, 2004 3:04 am
by patrikG
Try $_POST["username"] and have a look at viewtopic.php?t=511

Posted: Wed May 12, 2004 3:05 am
by patrikG
Gah, you beat me by a couple of seconds, markl999 ;) Yet again!