Reputation: 53
I have this simple form wich allows to search and I want to show results into a DIV, so I am using ajax for it.
<script type="text/javascript">
$(document).ready(function(){
$('#boton_cargar').click(function() {
var nombre = $("#nombre").val();
$.ajax({
type: "GET",
url: 'resultados.php?nombre='+nombre,
success: function(data) {
$('#resultados').html(data);
$('#resultados div').slideDown(1000);
}
});
});
});
</script>
<form>
<input id="nombre" name="nombre" type="text" />
<input name="boton_cargar" id="boton_cargar" type="button" value="buscar" />
</form>
<div id="resultados">
// I want to show results here
</div>
and this is resultados.php
<?php
include('loader.php'); //call db
$conn = new conection();
$rs = new RecordSet($conn);
if(isset($_GET['nombre']))
$sql="SELECT * FROM clientes INNER JOIN alquiler ON clientes.id_cliente = alquiler.id_cliente INNER JOIN insumos ON insumos.id_insumo = alquiler.id_insumo WHERE `clientes`.`nombre` = {$_GET['nombre']}";
else
die('error');
unset($rs);
unset($conn);
?>
<?php foreach($resultados as $res){ ?>
<?php echo $res->nombre ?>
<?php }?>
I don't know what it's wrong, for example if I replace {$_GET['nombre']} for "jhon" I can get the results.
Hope can help me, thank u so much in advance!
Upvotes: 0
Views: 194
Reputation: 823
Your problem is the query, that is not returning nothing because its format, try this:
$sql = "SELECT * FROM clientes INNER JOIN alquiler ON clientes.id_cliente = alquiler.id_cliente INNER JOIN insumos ON insumos.id_insumo = alquiler.id_insumo WHERE `clientes`.`nombre` = '".$_GET['nombre']."'";
I hope that can help you.
Upvotes: 0
Reputation: 1564
Try by replacing the sql line with this:
$sql="SELECT * FROM clientes INNER JOIN alquiler ON clientes.id_cliente = alquiler.id_cliente INNER JOIN insumos ON insumos.id_insumo = alquiler.id_insumo WHERE `clientes`.`nombre` = '" . $_GET['nombre'] . "'";
Upvotes: 0
Reputation: 9646
You need to put quotes around {$_GET['nombre']}
$sql="SELECT * FROM clientes INNER JOIN alquiler ON clientes.id_cliente = alquiler.id_cliente INNER JOIN insumos ON insumos.id_insumo = alquiler.id_insumo WHERE `clientes`.`nombre` = '{$_GET['nombre']}'";
Upvotes: 1