Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda