Form Data with OO PHP

Helo Friends , How are you?

I am ready to inform you how to use form data using PHP Class.

First of all, make a class named “myData”. Then follow the code here-

class myData{
    public $name;
    public $age;
    public $sex;

    public function setData($x, $y, $z)
        $this->name = $x;
        $this->age = $y;
        $this->sex= $z;



<!DOCTYPE html>


        //creating object now
        $data= new myData();


        echo "Hello ".$data->name.". Your are ".$data->age." years old. You are a ";
            echo "Male.";
            echo "Female.";



    <form name="" method="post">
        Name: <input type="text" name="myname" required 
placeholder="i.e. Mr. Suchi"/><br/>
        Age: <input type="text" name="myage" required 
placeholder="i.e. 22" /><br/>
        You are: <input type="radio" name="mysex" value="1" /> 
Male <input type="radio" name="mysex" value="2" />Female<br/>

        <input type="submit" name="submit" value="Show My Data"/>



Here is the code to access form data with object oriented PHP class.

Thanks for reading


1 Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s