getting error Undefined array key in php file with html forms

Viewed 436

I've got issues with sending data from a html list to a php file. here is my code:

`        <form method="post" action="file.php">
           field: <select type="text" name="name" > 
            <option value=”1” >No1 </option>
            <option value=”2” > No2</option>
            <option value=”3” >No3 </option>
            </select>
            <input type="submit" value="submit">
           </form>

and this is code in php file which receives the value:

$var = $_POST["name"];
echo $var;

but I'm getting error getting error Undefined array key "name". would be thankful if anybody could help me with this issue.

1 Answers

Use this instead:

$var = isset($_POST["name"] ) ? $_POST["name"]: '';
Related