-1
Here I have a code to open modal sending the collaborator to search in the file cadas.php and return in variables. Example: date.data6, date.Collaborator6, date.Observation6...
Doubt: I wanted to know how I do in php to assign the variables by making a query in the BD of a table and returning the data to the page with the variables.
$(document).on('click', '.edit_data6', function(){
var idcolaborador = $(this).attr("Id");
$.ajax({
url:"cadastro.php",
method:"POST",
data:{idcolaborador:idcolaborador},
dataType:"json",
success:function(data){
$('#data6').val(data.data6);
$('#Colaborador6').val(data.Colaborador6);
$('#Observacao6').val(data.Observacao6);
$('#Estado1').prop("checked", data.Estado);
$('#Conclusao').val(data.Conclusao);
$('#idcolaborador').val(data.Id6);
$('#insert6').val("Gravar");
$('#exampleModal6').modal('show');
}
});
});
<?php
$dados = filter_input_array(INPUT_POST, FILTER_DEFAULT);
$Query = mysqli_query($conexao,"SELECT * FROM colaboradores WHERE id='".$dados['idcolaborador']."'")or die(mysql_error()); ?>
while($row=mysqli_fetch_array($Query)){
$data6 = $row['data6'];
$Colaborador6 = $row['Colaborador6'];
$Conclusao= $row['Conclusao'];
$Id6= $row['Id6'];} ?>
dataType:"json"
, in AJAX you are expecting a JSON, so you need to make PHP respond with a JSON. Read about the functionjson_encode
of PHP.– Woss