0

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.

Community
  • 1
  • 1
  • 1
    did you clicked submit button without providing value to the input tags? – Santhosh Kumar Feb 13 '19 at 08:36
  • 1
    Can you show us what is output of `var_dump($_POST, $_GET);` in `valid.php` after you submit form? – Justinas Feb 13 '19 at 08:36
  • @SanthoshKumar In that scenario key would be still in `_POST`, but with empty values – Justinas Feb 13 '19 at 08:37
  • what does var_dump($_REQUEST); show? – Tali Luvhengo Feb 13 '19 at 08:37
  • 1
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Qirel Feb 13 '19 at 08:39

4 Answers4

0

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>
0

Try this

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

echo $Name;
echo $SurName;
VinothRaja
  • 1,405
  • 10
  • 21
0

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();
?>
Jahid Hasan
  • 533
  • 4
  • 9
0

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...