php query postgresql with return in ajax

0

I want to make a php / postgresql query and return the values in a form already filled with ajax, so that there is no page refresh where I can edit the information and update in the database. I can bring the form but the input comes empty.

On the main page I tried this:

<div id="principal">
<form method="post" enctype="multipart/form-data" id="edt" autocomplete="off">
<select id="selecao" name="selecao" onblur="run(this)">
<option value="1">Azul</option>
<option value="2">Amarelo</option>
<option value="3">Vermelho</option>
</select>
<br />
<button id="procura">Sel</button>
</div>

<script src="jquery.min.224.js"></script>
<script>
function run(sel) { 
    var text = $("#selecao").val();
        if (text != "") {
            $.ajax({
                type: "POST",
                url: "resultado.php",
                data: { selecao: text}
            })
            // done callback using data (wha
            .done(function(data) {              
                $("#edt")[0].form.reset();
            });
        }
}

$(document).ready(function() {
   $('#procura').click(function(){
      $('#principal').load('resultado.php #principal', function() {        
      });
   });
}); 

In the result.php page I have this:

<?php
include("banco.php");


if(isset($_POST["selecao"])){
    $qry = pg_query($dbconn,"select * from tabela where id = ".$_POST["selecao"]."") or die(pg_last_error($dbconn));
    $qryRow = pg_fetch_assoc($qry);
}
?>
<!doctype html>
<html>
<head>
<script src="../../../_jquery/jquery.min.224.js"></script>
<meta charset="utf-8">
<title>Documento sem título</title>
</head>

<body>
<div id="principal">
<form method="post" enctype="multipart/form-data" id="val" autocomplete="off">
ID: <input type="text" name="id" readonly value="<?php echo $qry['id'];?>"/>
<br />
COR: <input type="text" name="cor" readonly value="<?php echo $qry['cor'];?>"/>
<br />
STATUS: <input type="text" name="status" readonly value="<?php echo $qry['status'];?>"/>
</form>
</div>
</body>
</html>
    
asked by anonymous 11.05.2018 / 15:07

0 answers