html - Using the object operator in PHP -


i looked @ post try , understand object operator better: where use object operator "->" in php?

but when copied , pasted php in 2nd response, blank page when run it. here code:

php:

<?php      class simpleclass {     // property declaration     public $var = 'a default value';      // method declaration     public function displayvar() {         echo $this->var;     } }  $a = new simpleclass(); echo $a->var; $a->displayvar();  ?> 

html:

<!doctype html>  <html lang="en">     <head>         <meta charset="utf-8" />         <title></title>     </head>     <body>          <form action ="process.php" method ="post">             first name: <input type="text" name="fname">               <input type="submit">                </form>          <p>             click objectoperator.php             <button onsubmit="objectoperator.php">submit</button>         </p>     </body> </html> 

ignore form in html, else doing. when click on submit button want run php in objectoperator.php (which name of php file). when click nothing happens.

you can try this

i tried on phpfiddle , working

<?php class simpleclass { // property declaration public $var = 'a default value';  // method declaration public function displayvar() {     echo $this->var; } }  if ($_server['request_method'] == 'post') { $a = new simpleclass(); echo $a->var; $a->displayvar(); } ?>   <form action ="" method ="post">first name: <input type="text" name="fname">  <input type="submit">        </form> 

the key have correct action


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -