PHP OOP - get property of non-object and evaluation of code
Welcome. I have one problem with my PHP class.
Error:

Notice: Undefined variable: data in /home/marian/public_html/nauka/model/firma.php on line 25

Notice: Trying to get property of non-object in /home/marian/public_html/nauka/model/firma.php on line 25

Notice: Undefined variable: data in /home/marian/public_html/nauka/model/firma.php on line 26

Notice: Trying to get property of non-object in /home/marian/public_html/nauka/model/firma.php on line 26    


    <form action="#" method="post">
    Name <input type="text" name="name" > <br/>
    Adress <input type="text" name="adress" ><br/>

    <input type="submit" name="add" value="Add">
    </form>

    <?php

    class Company {

        public $name;
        public $adress;

    }

    class ModelCompany extends Company {

        public function insert() {
            try {
                $pdo = new PDO('mysql:host=localhost;dbname=serwis', 'root', '');
                $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

                $stmt = $pdo->exec("INSERT INTO firma SET
                            nazwa = '" . $data->name . "',  //error line
                            adres        = '" . $data->adress . "' //error line
              
          ");



                return $stmt;
            } catch (PDOException $e) {
                echo 'Database error PDO: ' . $e->getMessage();
            }
        }

    }

    if (isset($_POST['add'])) {
        $data = new Company();
        $data->name = $_POST['name'];
        $data->adress = $_POST['adress'];
        $model = new ModelCompany();
        $model->insert();
    }

Please evaluation of code. This is good OOP code? 
PHP OOP - get property of non-object and evaluation of code
===

Welcome. I have one problem with my PHP class.
Error:

Notice: Undefined variable: data in /home/marian/public_html/nauka/model/firma.php on line 25

Notice: Trying to get property of non-object in /home/marian/public_html/nauka/model/firma.php on line 25

Notice: Undefined variable: data in /home/marian/public_html/nauka/model/firma.php on line 26

Notice: Trying to get property of non-object in /home/marian/public_html/nauka/model/firma.php on line 26    


    <form action="#" method="post">
    Name <input type="text" name="name" > <br/>
    Adress <input type="text" name="adress" ><br/>

    <input type="submit" name="add" value="Add">
    </form>

    <?php

    class Company {

        public $name;
        public $adress;

    }

    class ModelCompany extends Company {

        public function insert() {
            try {
                $pdo = new PDO('mysql:host=localhost;dbname=serwis', 'root', '');
                $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

                $stmt = $pdo->exec("INSERT INTO firma SET
                            nazwa = '" . $data->name . "',  //error line
                            adres        = '" . $data->adress . "' //error line
              
          ");



                return $stmt;
            } catch (PDOException $e) {
                echo 'Database error PDO: ' . $e->getMessage();
            }
        }

    }

    if (isset($_POST['add'])) {
        $data = new Company();
        $data->name = $_POST['name'];
        $data->adress = $_POST['adress'];
        $model = new ModelCompany();
        $model->insert();
    }

Please evaluation of code. This is good OOP code? 