Skip to content Skip to sidebar Skip to footer

$_post Undefined Index Php Error

My html code which receives the string: title

Solution 1:

You're re-using the action attribute on the form element:

<formaction="process.php"action="post">

I'm surprised the form is even posting at all given that. Though given the symptoms it seems to at least be enough to confuse the POST. I think you meant to use the method attribute:

<formaction="process.php"method="post">

A couple other notes:

  • You'll want to make use of isset() in your server-side code. The code shouldn't assume that all values will be posted, since the server can't control what a client sends it. Best to explicitly validate the data coming in before using it.
  • font elements are pretty dated, and if they're not officially deprecated they should be :) CSS styling would be the way to go for client-side UI styles.

Solution 2:

use isset

if(isset($_POST["sgst"]=="john")){

} 

Solution 3:

it shows undefined because at first the value is not initialized

use isset() inorder to check for value declared or not then it wont show error...

try this i have changed

<?PHPif (isset($_POST["sgst"])
{
   if ($_POST["sgst"]=="john") {
    echo"john";
   } else {
    echo"someone";
   }
}
?>

Solution 4:

Try following

use Method attribute like method="post"in form tag instead of action="post"

Solution 5:

You are missing method attribute.

Using two forms- Remove first form.

Try this,

<formaction="process.php"method="post"><?phpif(!empty($_POST)){
        if ($_POST["sgst"]=="john") {
                echo"john";
            } else {
                echo"someone";
            }
        }
        ?>

Post a Comment for "$_post Undefined Index Php Error"