newbi need help!! why the name cannot display after submit ?

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
User avatar
newbi
Forum Newbie
Posts: 11
Joined: Thu Jan 08, 2004 12:58 am
Contact:

newbi need help!! why the name cannot display after submit ?

Post by newbi »

<HTML>
<FORM>
please enter name :<BR>
<INPUT TYPE="text" NAME="username"><BR><BR>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>

<BR>
<?php
echo($username);
?>
</HTML
User avatar
newbi
Forum Newbie
Posts: 11
Joined: Thu Jan 08, 2004 12:58 am
Contact:

Post by newbi »

what happen to this simple program ? i dont understand why the username cannot pass over to display in php code.

can anyone tell me ? or just test the simple program.
sorry for disturb all here !
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

You didn't provide a method for the forum, so it's likely to go into $_GET mode. Do:

Code: Select all

print $_POST['username'];
and have a read at:
viewtopic.php?t=511

-Nay
User avatar
newbi
Forum Newbie
Posts: 11
Joined: Thu Jan 08, 2004 12:58 am
Contact:

Post by newbi »

it still does't work !

if i enter lengchai in the input textbox
the only changes will be the url :
http://localhost/test.php?username=lengchai


but i still cant display "lengchai"
User avatar
newbi
Forum Newbie
Posts: 11
Joined: Thu Jan 08, 2004 12:58 am
Contact:

Post by newbi »

OKOK thanks Nay Master
reading my stupid questiong i did solve the problem.
thank you very much !
: )
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Leng Chai? Cantonese? haha.......lei leng meh?

Anyhow like I said, that's because you didn't specify the method.

Code: Select all

print $_GET['username'];
by right it should be:

Code: Select all

<?php

if(isSet($_POST['submit']) {
echo $_POST['username'];
} else {
echo <<< FORM
<form id="form" action="test.php" method="post">
<input type="text" name="username" />
<input type="submit" value="Submit" />
<form>
FORM;
}

?>
-Nay
Post Reply