Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
传递变量-Ajax和Php_Php_Jquery_Ajax - Fatal编程技术网

传递变量-Ajax和Php

传递变量-Ajax和Php,php,jquery,ajax,Php,Jquery,Ajax,我有一个简单的表单,它允许搜索,我想把结果显示在一个DIV中,所以我使用ajax <script type="text/javascript"> $(document).ready(function(){ $('#boton_cargar').click(function() { var nombre = $("#nombre").val(); $.ajax({ type: "GET",

我有一个简单的表单,它允许搜索,我想把结果显示在一个DIV中,所以我使用ajax

<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>

$(文档).ready(函数(){
$('boton_cargar')。单击(函数(){
var nombre=$(“#nombre”).val();
$.ajax({
键入:“获取”,
url:'resultados.php?nombre='+nombre,
成功:函数(数据){
$('#resultados').html(数据);
$('resultados div')。向下滑动(1000);
}  
});  
});  
});  
//我想在这里展示结果
这是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 }?>

您需要在
{$\u 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']}'";

尝试将sql行替换为以下内容:

$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'] . "'";

您的问题是查询没有返回任何内容,因为其格式不同,请尝试以下操作:

$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']."'";

我希望这能对您有所帮助。

警告您的代码容易受到sql注入攻击!在哪里执行
$sql
$resultados
的定义在哪里?请不要使用
{$\u GET['nombre']}
试试
“$\u GET['nombre'].”“
谢谢您的回答!我尝试使用两个变量,可能我做得不对,因为它不工作url:'resultados.php?nombre='+nombre'&insumos='+insumos,