Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
My interaction between PHP and JavaScript is not working . What can i do to solve this?

I am echoing in the screen the (id,name,city) from MySQL.

But the problem and the challenge is inserting the values from MySQl into some inputs.

I am using the code:

verificar_id($pdo);

function verificar_id($pdo){
if(isset($_POST['verificar']) && isset($_POST['id_cliente'])){
    session_start();

    $id_cliente = $_POST['id_cliente'];

    $sql= $pdo->prepare("SELECT * FROM `clientes` where `id`=?");
    $sql->execute(array($id_cliente));

    $info = $sql->fetchAll(PDO::FETCH_ASSOC);

    echo "<pre>";
    print_r($info);
    echo "</pre>";

    foreach ($info as $key => $value) {
        $_SESSION['id'] = $value['id'];
        $_SESSION['nome'] = $value['nome'];
        $_SESSION['cidade'] = $value['cidade'];
    }
}
}


?>

 <script type='text/javascript'>
 var nome = document.getElementById('id').value = "<?php echo $_SESSION['id'] ?>"
 var nome = document.getElementById('nome').value = "<?php echo $_SESSION['nome'];?>"
 var nome = document.getElementById('cidade').value = "<?php echo $_SESSION['cidade'];? 
 >"
 </script>

And My HTML:

<body>
<form method="post" id="form">
    <input type="number" name="id_cliente">
    <input type="submit" name="verificar">
</form>
<input type="text" name="id" id="id">
<input type="text" name="nome" id="nome">
<input type="text" name="sobrenome" id="cidade">
</body>

And this is the result: enter image description here

How you can see the result is almost exactly what i wanted: The only problem in all this is the browser is not doing what should do. Of some how, the browser is understanding that this a Js code(and inside the code, it is appearing the same result tha the "print_r", but is not running and i don't know how to solve this.

Someone can help me to solve this problem? Or solve this or show another way to me get the result? Pls.

Maybe another way to insert the values into a input.

almost 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda