Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8803793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:26:04+00:00 2026-06-14T01:26:04+00:00

I am having troubles getting the value from my variables submitted via a web

  • 0

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:26:05+00:00Added an answer on June 14, 2026 at 1:26 am

    _setTitle() should have only one argument, and remove the second $ character in the assignment statement (also for getTitle()), like so:

    function _setTitle($title)
    {
        $this->title = $title;
    }
    

    Now call it like this:

    $title = !empty($_POST["title"]) ? $_POST["title"] : NULL;
    $bookNow->_setTitle($title);
    

    And don’t use double underscore unless you are dealing with magic functions. I think that is bad practice. Also check the case of your class – even though php is very relaxed about case. If your class file is called “Book.php” then your constructor should be called with uppercase just to make sure (and parentheses too probably).

    EDIT: OK this is the class I made and it works just fine, I tested it:

    class Book {
    
        private $title;
    
        function __construct() {}
    
        function _getTitle($title)  {
            return $this->title;
        }
    
        function _setTitle($title) {
            $this->title = $title;
        }
    
        public function printDetails() {
            echo "Title: " . $this->title . "<br />";
        }
    
    }
    

    Make sure you get a value in the POST, like this:

    $title = !empty($_POST["title"]) ? $_POST["title"] : 'No Title Found!';
    $bookNow = new Book();
    $bookNow->_setTitle($title);
    $bookNow->printDetails();
    

    NB: DO NOT put the above statements inside the ‘book.php’ class file.

    If your form submission went wrong, you will see ‘No Title Found!’, otherwise you will see the correct title.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently having troubles getting results from a simple aggregate function with HQL. Here is
I'm having trouble with a LINQ to SQL query getting the min value using
I'm having trouble getting the value of a custom prompt in PHP. I actually
Having trouble getting my POST arrays to show all checkbox values from my form.
I'm having trouble getting two variables to post using ajax and jquery upon pressing
I am having trouble getting Wordpress to assign the proper values to variables using
I'm having trouble getting a value from an xml string. $query_return_string contains the following
I'm having trouble getting the value of the last insert Id from doctrine. I
i'm having trouble getting the date to be imported into mysql from my form.
I am currently having trouble getting a value from an AsyncTask that gets data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.