Search for variable value

Asked

Viewed 41 times

0

Personal I have a form for candidate registration. To save in the bank it passes the values by javascript for the salvaCandidato.php. I’m trying to make the form to appear the modal saying the registration protocol that is in the variable $nr_prot in salvaCandidato.php, I’m not getting through.

index php.

    <div class="modal fade" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Observação</h4>
      </div>
      <div class="modal-body">
        <h4>Anote seu protocolo</h4>
        <h4>$nr_prot</h4>
        <h4> O protocolo foi enviado para o email </h4>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
      </div>
    </div>
  </div>
</div>

salvaCandidato.php

  $sqlProt = "SELECT * FROM candidato WHERE cpf_cand = '$_POST[cpf_cand]'";
  $queryProt = mysqli_query($conexao,$sqlProt);
  $fetchProtocolo = mysqli_fetch_assoc($queryProt);
  $nr_prot =  $fetchProtocolo['nr_prot'];

  • You cannot put a PHP variable inside pure HTML like you did <h4>$nr_prot</h4>. If the modal opens in PHP you need to use <h4><?php echo $nr_prot;?></h4>

  • It was just to illustrate, I tried to use $_SESSION and $_POST, but it doesn’t come

  • You will have to put the protocol number in the modal via javascript. See an example $("#modal-body"). html('your protocol number');

1 answer

0

It can be done as follows:

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

You will edit only the variaveljs and put your variable!

.

I don’t know if I can help you, but I hope so!

  • In case, as will be the varivaljs, I could not test, already thank

  • From your html code <script>var variaveljs = "Your var";</script> , use the above code to take the js variable for php, and to print out what you want, use: <H4><? php echo $nr_prot; ? ><H4>, as presented in the commentary above!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.