How to send variables from php to html page?

-1

I'm creating a test page to see if I can use it, learn it, and then move it to a larger project.

My problem is this: I create the submission form in HTML, I do the search in BD with PHP, but I can not return the search result in PHP to PHP

HTML:

<html>
<head>
  <meta charset="utf-8" />
  <title>Teste</title>
</head>

<body>
    <form action="teste.php ">
        <input type="submit" name="Pesquisar"/>
    </form>
</body>
</html>

PHP

<?php 
    $conexao = mysqli_connect('localhost','root','','login_sessao');

    $consulta = mysqli_query($conexao, "SELECT usu_Senha FROM tb_usuario where usu_Email = 'emailQualquer'");

    $consultaQ = mysqli_fetch_assoc($consulta);
    echo "Sua senha é: " + $consulta['usu_Senha'];
?>

Sorry if you're formatted wrong, first time asking a question, but thank you right away.

    
asked by anonymous 07.12.2018 / 02:16

2 answers

1

The concatenation operator of strings in PHP is the point : . !

See an example:

<?php
$string = 'texto qualquer';

echo 'Este é um ' + $string; // Exibe "0"
echo 'Este é um ' . $string; // Exibe "Este é um texto qualquer"
  

Recommended reading: PHP - String Operators

If this does not solve your problem, post the output of your query (PHP warnings, errors, etc.).

    
07.12.2018 / 02:46
1

All good! Next, the various ways you can output PHP data to HTML! The simplest way is to create the query in the file itself and then "draw" the table by getting the array that comes from the Database! Another way would be to use query by ajax method. In the ajax method you trigger the query to a link and this link you return already the mounted table and points to a DIV.

In the code below I use JavaScript with Ajax, I point out what my variable is of the type value, I would point out what my page would be in php and return the data in the div #dates. Inside the file buscateste.php I create the query in php with the mysql database and then I create a table in html showing the query data

function buscaTipo(){

    var valorTipo = document.getElementById('tipo').value;
    var page = "buscateste.php";

    if(valorTipo !=''){
      $.ajax ({
        type: 'POST',
        dataType: 'html',
        url: page, beforeSend: function(){
          $("#dados").html("Carregando...");
        },
        data: {valorTipo: valorTipo,
          opcao: 1},
        success: function(msg)
        {
          $("#dados").html(msg);
        }
      })
    }else{
      $.post('buscateste.php', function(retorna){
        $("#dados").html(retorna);
    });

}}
    
07.12.2018 / 17:15