Unable to Get values from Web Form to a PHP Class to Display
Posted
by
kentrenholm
on Stack Overflow
See other posts from Stack Overflow
or by kentrenholm
Published on 2012-11-04T10:39:01Z
Indexed on
2012/11/04
10:59 UTC
Read the original article
Hit count: 199
I am having troubles getting the value from my variables submitted via a web form using a PHP class file.
Here is my structure of the web page:
- Order Form Page
- Process.php Page
- Book.php Page
I can easily get the user data entered (on Order Form Page), process, and display it on the Process.php page. The issue is that I must create a Book class and print the details of the data using the Book class.
I have an empty constructor printing out "created" so I know my constructor is being called. I also am able to print the word "title" so I know I can print to the screen by using the Book class.
My issue is that I can't get values in my variables in the Book class.
Here is my variable declaration:
private $title;
Here is my printDetails function:
public function printDetails () {
echo "Title: " . $this->title . "<br />";
}
Here is my new instance of the book class:
$bookNow = new book;
Here are my get and set functions:
function __getTitle($title)
{
return $this->$title;
}
function __setTitle($title,$value)
{
$this->$title = $value;
}
I do have four other variables that I'm looking to display as well. Each of those have their own variable declaration, a line in printDetails, and their own setter and getter.
Lastly, I also have a call to the Book class in my process PHP. It looks like this:
function __autoload($book) {
include $book . '.php';
}
$bookNow = new book();
Any help, much appreciated. It must be something so very small (I'm hoping).
© Stack Overflow or respective owner