简体   繁体   中英

PHP form post undefined index

I have an issue about HTML post to PHP script. But the values are not posted. My form.php file codes are;

<form action="http://xxxx/valid.php" method="post">

    Name: <input name="Name" value='' type="text" />
    Sur Name: <input name="SurName" value='' type="text" />

    <input id="submit" type="submit" value="Send" />
</form>

and valid.php codes are;

<?php

echo $_POST["Name"];
echo $_POST["SurName"];
foreach($_POST as $key=>$value)
{
    echo "$key=$value";
}

die();
?>

I get the blank page and I get this error.

Undefined index: Name Undefined index: SurName

I working on PHP 5.6 What is wrong?

Its Solved ! Changed the http://xxxx/valid.php to /valid.php and its worked.

Try This One.

<form action="http://xxxx/valid.php" method="post">

    Name: <input type="text" name="Name" value=''  />
    Sur Name: <input type="text" name="SurName" value=''/>

    <input id="submit" type="submit" value="Send" />
</form>

Try this

$Name = isset($_POST['Name']) ? $_POST['Name'] : '';
$SurName = isset($_POST['SurName']) ? $_POST['SurName'] : '';

echo $Name;
echo $SurName;

try this in valid.php file:

<?php
if(isset($_POST["Name"]) && isset($_POST["SurName"])){
    echo $_POST["Name"];
    echo $_POST["SurName"];
    foreach($_POST as $key=>$value)
    {
        echo "$key=$value";
    }
}
die();
?>

I tested your code, all is working fine with me. if the code is correct then the issue is in the configuration of server or installation (something like that.)

check your configuration maybe it can help...

Well if it's solved then cheers...

happy coding...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM