Jump to content

php5 $_POST


Terramoto

Recommended Posts

hi, i made a simple php page:
[quote]<?php
echo $_POST["username"];
?>
<form action="this.php" method="POST" enctype="text/plain">
<input type="text" name="username" size="40" maxlength="40"/>
<input type="submit" name="submit" value="Login"/>
</form>[/quote]
im using php 5.2.0 and apache 2.0.59,
and the $_POST returns nothing...any hint?
,tks
Link to comment
https://forums.phpfreaks.com/topic/29809-php5-_post/
Share on other sites

Code looks fine except it will generate a notice until the form is submitted. What does this output?

[code]
<?php
  print_r($_POST);
?>
<form action="this.php" method="POST" enctype="text/plain">
  <input type="text" name="username" size="40" maxlength="40"/>
  <input type="submit" name="submit" value="Login"/>
</form>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29809-php5-_post/#findComment-136885
Share on other sites

You can do:

[code]
<?php
if(!isset($_POST[username]){
echo "<form action=this.php method=POST>\n";
echo "<input type=text name=username size=40 maxlength=40/>\n";
echo "<input type=submit name=submit value=Login/>\n";
echo "</form>\n";
}else {
echo "$_POST[username]";
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29809-php5-_post/#findComment-136896
Share on other sites

^^ With all in mind, code will be:
[code]
<?php
if (isset($_POST["username"]))
{
    echo $_POST["username"];
}
else
{
echo ' <form action="this.php" method="POST" >
  <input type="text" name="username" size="40" maxlength="40"/>
  <input type="submit" name="submit" value="Login"/>
</form>';
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29809-php5-_post/#findComment-136904
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.