title: PHP Object Can't Call Function Inside If Statements
body: <p>please point out the obvious as I just started learning about OOP in PHP. My class <code>books</code> contains two public functions: one to display a request books form, and the other to submit the book details to my database. I use two <code>if</code> statements to call these functions when the user clicks the <code>request book</code> or <code>submit form</code> buttons. </p>
  
  <p>Here is my class: </p>
  
  <pre><code>class Book
  {
      public $title;
      public $author;
      public $id;
  
      public function SendToDatabase()
      {
          echo "inside SendToDatabase";
      }
  
      public function Display()
      {
          echo "&lt;form action='' method='post'&gt;
      Title: &lt;input type='text' name='title'&gt;&lt;br&gt;
      Author: &lt;input type='text' name='author'&gt;&lt;br&gt;
      &lt;input type='submit' name='submitBook' value='submit'&gt;
      &lt;/form&gt;";
      }
  
  }
  </code></pre>
  
  <p>And here is my code to call the functions using buttons (in the same file). As is, the <code>SendToDatabase()</code> function is never called. I am able to get it working when I combine the <code>if</code> statements, but then the buttons would not work properly. I am a little confused because I thought the scope of the object is the same across if statements. I would really appreciate anyone pointing out my mistake. Cheers.</p>
  
  <pre><code>echo "&lt;form action='' method='post'&gt;&lt;input type='submit' name='submit' value='Request Book'&gt;&lt;/form&gt;";
  $request = $_POST['submit'];
  $submit  = $_POST['submitBook'];
  if ($request) {
      $book = new Book();
      $book-&gt;Display();
  }
  
  if ($submit) {
      $book-&gt;SendToDatabase();
  }
  </code></pre>