Pass Value By PHP PHP parameter [duplicate]

0

I have a small snippet of code, just below.

After the user clicks on a div whose ID is (click) this code will be executed. I have a PHP code that will run inside the javascript code block. I want to pass to the PHP JavaScript variable (Value) in the method parameter $ status-> checkUserType (), getting $ status-> checkUserType (value). It's possible?

           $('#click').click(function () {

            var valor='exemplo';


           var recebePHP= "<?php
            $status= new Usuario_Control_Grupo();
            $status->verificarTipoUsuario();

            if($status==true) {
                echo 'existe';
            }else{echo 'inexistente';}

            ?>";
             });
    
asked by anonymous 28.05.2018 / 16:55

1 answer

1

When you use the web you are using HTTP client-server communication. This means that you perform an HTTP request to the server. The server in turn takes its request and returns a response, usually an HTML file. That is interpreted by your browser.

Once the server returns the response it is impossible for PHP to change some value without another request. That's why your code will never work like this.

You have to create a separate PHP file that ONLY writes that result you want. Inside the page you do the check you should make a Javascript request for this file.

Search for:

  • Using Fetch Javascript
  • Simple Ajax with PHP
  • Server Client Communication.
29.05.2018 / 02:39