Access Local variable in JavaScript and store in PHP variable [duplicate]

-3

Good evening!

How could I store the data of the variable "test" in "$ variavelphp". The way the code today is the variable "test" is not accessible.

If it is not possible how could I access the value of the variable "test" in "test2" in another part of the code.

                var ref = firebase.database().ref('Profissionais').orderByChild('Nome');


                //var u = 0;

        ref.on('child_added', function (snapshot) {
            var profissional = snapshot.val();
            if (profissional.provider == "usuarios" || profissional.provider == "Facebook" || profissional.provider == "Firebase" || profissional.provider == "Usuarios") {
                 teste =  "<tr><td>" + snapshot.key + "</td><td>" + profissional.Nome + "</td><td>" + profissional.Email + "</td><td>" + profissional.provider + "</td><td><a href='usuario.php?id=" + snapshot.key + "' class='btn btn-round btn-fill btn-info'>Consultar</a></td></tr>";


            }



            });



</script>


    <?php
        $variavelphp = "<script>document.write(teste)</script>";

        ?>

<script type="text/javascript">

var teste2 = teste;

alert(teste2);



</script>
    
asked by anonymous 25.10.2018 / 05:10

1 answer

-1

Good day, my friend. I suggest, after getting the data from Firebase, you do a post / get to a page in PHP and get the data from the request itself.

If it's GET, it would look like this:

$variavel = $_GET['teste'];

If it's POST:

$variavel = $_POST['teste'];

In this way, you can pass the information from Javascript to PHP. But only with requests: POST, GET, PUT, etc.

I hope I have helped.

    
25.10.2018 / 15:49