$ _POST ['变量'],变量无法识别(“未定义索引”)[关闭]

I am trying to learn PHP (just a tiny bit for a tiny project). I am trying to follow this tutorial, but when I do, it does not work. First of all I coppied the exact code there and it still did not work, but here is some of my code:

    <?php
         if($_POST['projectSubmit'] == "Submit") 
        {
            $toApprove= $_POST['projectName'];
        }
    ?>


    <form action ="getData" method="post" >
        <input type="text" name="projectName">
        <input type="submit" name="projectSubmit" value="Submit">
    </form>

Yet I get an error:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: projectSubmit

Filename: views/ViewProjectApproval.php

Line Number: 13

What am I doing wrong ?

BTW: Is this a correct way of transmitting data back to my controller ? (model view controller with code igniter)

Use this

if (isset($_POST['projectSubmit']) && $_POST['projectSubmit'] == "Submit") 

Use:

if (isset($_POST['projectSubmit'])) { /*...*/ }

This checks if the parameter is sent. (here: when the form was submitted)