I'm developing an application in which I have multiple tables and dialogs using form.serialize()
, but that particular one is not working and I can not find the reason.
Form:
<form id="formDialogOrdemServicoBuscaTopo">
<span class="container">
<span>
<select id="selectOrdemServicoPesquisa" name="selectOrdemServicoPesquisa">
<option value="numero">Número</option>
<option value="cliente">Cliente</option>
<option value="dataAbertura">Data Abertura</option>
<option value="dataFechamento">Data Fechamento</option>
<option value="equipamento">Equipamento</option>
<option value="modelo">Modelo</option>
<option value="nserie">Nº de Série</option>
</select>
</span>
<span> </span>
<span>
<input type="text" id="inputOrdemServicoPesquisa" name="inputOrdemServicoPesquisa">
</span>
<span> </span>
<span><button id="buttonOrdemServicoListaTipoPesquisa">Buscar</button></span>
</span>
</form>
Javascript Code:
$("#buttonOrdemServicoListaTipoPesquisa").off("click").on("click", function(event){
event.preventDefault();
$.ajax({
url : "ordemServicoCadastroBuscaTopo.php",
type: "POST",
dataType: "json",
data : $("#formDialogOrdemServicoBuscaTopo").serialize(),
success: function(data)
{
$("#divListaOrdemServico").html('');
$.each(data, function(index, val) {
$("#divListaOrdemServico").append("<tr><td>"+val.id+
"</td><td>"+val.nome+"</td><td>"+val.equipamento+"</td><td>"+val.marca+"</td><td>"+val.modelo+"</td><td>"+val.nserie+"</td><td>"+val.dataAbertura+"</td><td>"+val.dataFechamento+"</td></tr>"
);
});
},
error: function (jqXHR, textStatus, errorThrown)
{
alert( jqXHR.responseText);
}
});
});
PHP Code:
<?PHP
header('Content-Type: application/json');
include("dbConn.php");
$tipoPesquisa = $_POST['selectOrdemServicoPesquisa'];
$dadoPesquisa = $_POST['inputOrdemServicoPesquisa'];
if($tipoPesquisa == 'numero')
$sqlSelect = "SELECT * FROM 'ordemservico' WHERE id LIKE '%$dadoPesquisa%'";
if($tipoPesquisa == 'cliente')
$sqlSelect = "SELECT * FROM 'ordemservico' WHERE tipo LIKE '%$dadoPesquisa%'";
if($tipoPesquisa == 'equipamento')
$sqlSelect = "SELECT * FROM 'ordemservico' WHERE equipamento LIKE '%$dadoPesquisa%'";
if($tipoPesquisa == 'modelo')
$sqlSelect = "SELECT * FROM 'ordemservico' WHERE modelo LIKE '%$dadoPesquisa%'";
if($tipoPesquisa == 'nserie')
$sqlSelect = "SELECT * FROM 'ordemservico' WHERE nserie LIKE '%$dadoPesquisa%'";
if($tipoPesquisa == 'dataAbertura')
$sqlSelect = "SELECT * FROM 'ordemservico' WHERE dataAbertura LIKE '%$dadoPesquisa%'";
if($tipoPesquisa == 'dataFechamento')
$sqlSelect = "SELECT * FROM 'ordemservico' WHERE dataFechamento LIKE '%$dadoPesquisa%'";
if($tipoPesquisa == '')
$sqlSelect = "SELECT * FROM 'ordemservico' ORDER BY nome ASC";
$result = mysqli_query($conn, $sqlSelect);
$rows = array();
while($row = mysqli_fetch_assoc($result)){
$rows[] = $row;
}
echo json_encode($rows);
mysqli_close($conn);
?>
Error returned:
<br />
<b>Notice</b>: Undefined index: selectOrdemServicoPesquisa in <b>Z:\web\ManutencaoNET\ordemServicoCadastroBuscaTopo.php</b> on line <b>5</b><br />
<br />
<b>Notice</b>: Undefined index: inputOrdemServicoPesquisa in <b>Z:\web\ManutencaoNET\ordemServicoCadastroBuscaTopo.php</b> on line <b>6</b><br />
<br />
<b>Warning</b>: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in <b>Z:\web\ManutencaoNET\ordemServicoCadastroBuscaTopo.php</b> on line <b>35</b><br />