Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
我的php表单没有传递数据,因为我已经实现了自动建议_Php_Jquery_Mysql_Forms_Autosuggest - Fatal编程技术网

我的php表单没有传递数据,因为我已经实现了自动建议

我的php表单没有传递数据,因为我已经实现了自动建议,php,jquery,mysql,forms,autosuggest,Php,Jquery,Mysql,Forms,Autosuggest,这是我的场景,一切正常,根据我在搜索表单中输入的内容,显示了相应的图像。但由于我在我的网站上添加了自动建议功能,似乎无论我在搜索框中写什么并按下搜索,我认为我的输入表单都没有向php发送数据。因为即使我在表单中输入了一些东西,这个条件仍然是错误的。 ($name包含用户输入的值): 这是我的html表单: <form class="searchform" action="webpage.php" method="POST"> <input class="searchfield

这是我的场景,一切正常,根据我在搜索表单中输入的内容,显示了相应的图像。但由于我在我的网站上添加了自动建议功能,似乎无论我在搜索框中写什么并按下搜索,我认为我的输入表单都没有向php发送数据。因为即使我在表单中输入了一些东西,这个条件仍然是错误的。 ($name包含用户输入的值):

这是我的html表单:

<form class="searchform" action="webpage.php" method="POST">
<input class="searchfield autosuggest" type="text"  placeholder="Search for a name " onFocus="if (this.value == 'Search...') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Search...';}" />
<input class="searchbutton" type="submit" value="Go" />
</form>

我为自动建议添加的最新脚本如下:

  //Autosuggest starts here


$(document).ready(function(){
$('.autosuggest').keyup(function(){


var search_term= $(this).attr('value');
$.post('search.php',{search_term:search_term},function(data){

    $('.results').html(data);

    $('.results li').click(function(){
        var result_value = $(this).text();
        $('.autosuggest').attr('value',result_value);
        $('.results').html('');
    });

});

});
});

</script> 
//自动建议从这里开始
$(文档).ready(函数(){
$('.autosuggest').keyup(函数(){
var search_term=$(this.attr('value');
$.post('search.php',{search\u term:search\u term},函数(数据){
$('.results').html(数据);
$('.results li')。单击(函数(){
var result_value=$(this).text();
$('.autosuggest').attr('value',result_value);
$('.results').html('');
});
});
});
});
最后,这是另一个search.php文件,用于通过数据库查询autosuggest:

if(isset($_POST['search_term'])== true && empty($_POST['search_term'])== false)
{
    $search_term = mysql_real_escape_string($_POST['search_term']);
    $query = mysql_query("select * from user_info where Name LIKE '$search_term%'");

    while(($rows = mysql_fetch_assoc($query))!== false)
    {
    echo '<li>'.$rows['Name'].'</li>';
    }
}
if(isset($\u POST['search\u term'])==true&&empty($\u POST['search\u term'])==false)
{
$search\u term=mysql\u real\u escape\u字符串($\u POST['search\u term']);
$query=mysql\u query(“从用户信息中选择*,其中名称类似于“$search\u term%”);
while(($rows=mysql\u fetch\u assoc($query))!==false)
{
回显“
  • ”.$rows['Name']”。
  • ; } }

    现在,自动建议正在工作,但不是主站点。这可能是我的图像定位问题还是php没有从输入表单接收数据?

    您应该在输入框中添加name属性

    哦,非常感谢,我在输入表单和提交表单中都添加了name属性。让它工作起来。你能解释一下为什么总是需要name属性吗?这样你就可以控制数据传递了。我必须说Stackoverflow&这里的人非常乐于帮助别人。我在这里总是得到快速和积极的回应。愿上帝保佑你们所有人1!!我想再做一件事。您已经看到了我上面的代码,如果我想在用户单击下拉列表中的任何一个时将数据传递给php,该怎么办。现在,如果用户单击列表中的某个名称,该名称将进入字段,用户必须按下搜索按钮才能传递数据。我可以通过单击来执行这两个操作吗?怎么做?只要问一个新问题就行了^^
    if(isset($_POST['search_term'])== true && empty($_POST['search_term'])== false)
    {
        $search_term = mysql_real_escape_string($_POST['search_term']);
        $query = mysql_query("select * from user_info where Name LIKE '$search_term%'");
    
        while(($rows = mysql_fetch_assoc($query))!== false)
        {
        echo '<li>'.$rows['Name'].'</li>';
        }
    }