Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!