Forum : OOPS query
Brief description  about Online courses   join in Online courses
View Pradeep  Kumar 's Profile

OOPS query

Can we assign form variable values to a php class variables ?
I tried using
class a {
var $input = $_POST['input'];

but it is showing... parse error
Asked by Pradeep Kumar | Dec 7, 2009 |  Reply now
Replies (2)
View pradeep kumar 's Profile
got it... thanks sanjay
Dec 8, 2009
View sanjay s nair 's Profile
It is not possible.
You have to create a class containing that variable as member variable, and a member function to assign value to those variables.

Check the below code. I haven't tested it. In a nuttshell works somewhat like that.

<?php

/* Class Starts here */
class member{

var $name;
var $age;

function assignData($n,$a){
$this->name = $n;
$this->age = $a;
}

}
/* Class ends here */





//Here gets the post from some other page
$membername = $_POST['name'];
$memberage = $_POST['age'];

//Creates new object of member class defined above
$object = new member();

//Calls assignData function to assign variable values posted from previous page
$object->assignData($membername,$memberage);

//Prints the data
echo $object->name;
echo "<br>";
echo $object->age;



?>
Dec 8, 2009