我的搜索结果不一致?为什么是这样? [英] My search results aren't consistent? Why is this?

查看:105
本文介绍了我的搜索结果不一致?为什么是这样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在练习使用php mysql的搜索结果。我收到的唯一问题是搜索结果不一致。



请访问:

weezy.co.uk/newresults.php



在顶部的第一个搜索框中键入'学员'。
有时结果显示有时他们没有。我不明白这一点吗?



我的HTML搜索框代码是:

 < form action =newresults.phpmethod =postname =form> 
< input type =textid =searchname =search
size =30value =style =background-color:white; border:
solid 1px #ffffff; height:30px; font-size:19px; font-family:
HelveticaNeue-Light; font-weight:1;
vertical-align:9px; color:#151515
onfocus =if(this.value ==''){this.value =
''; this.style.color ='#363D42'}/>
< / div>
< / div>
< div class =search>
< div class =search1>
< input type =text
id =searchtermname =searchtermsize =25value =style =background-
color:white; border:
solid 1px #ffffff; height:30px; font-size:19px; font-family:
HelveticaNeue-Light; font-weight:1;
vertical-align:9px; color:# 151515
onfocus =if(this.value ==''){this.value =
''; this.style.color ='#363D42'}/>
< / form>

php code:

 <?php 

$ conn = mysql_connect(,,);

if(!$ conn){
echo无法连接到DB:。 mysql_error();
出口;
}

{

$ search =%。 $ _POST [搜索]。 %;
$ searchterm =%。 $ _POST [searchterm]。 %;


$ b if(!mysql_select_db(weezycouk_641290_db1)){
echo无法选择mydbname:。 mysql_error();
出口;

$ b $ sql =SELECT姓名,姓氏,电子邮件
FROM test_mysql
姓名LIKE'$ search%'和姓氏LIKE'$ searchterm%'' ;

$ result = mysql_query($ sql);

if(!$ result){
echo无法成功从DB运行查询($ sql):。 mysql_error();
出口;
}

if(mysql_num_rows($ result)== 0){
echo找不到行,不需要打印,所以正在退出;
出口;


$ b while($ row = mysql_fetch_assoc($ result)){
echo'< br>';
echo'< br>';
echo'< div class =data1>';
echo $ row [name];
echo'< / div>';
echo'< br>';
echo'< div class =data2>';
echo $ row [lastname];
echo'< / div>';
echo'< br>';
echo'< div class =data3>';
echo $ row [email];
echo'< / div>';
}

mysql_free_result($ result);

?>

谢谢你们!



当您的网页加载结果时,您还会加载一个标签边栏,其中带有希望招聘人员找到您?的问题。该侧栏中的输入框填入输入名称和输入所选行业。这两个输入的名称属性是搜索,因此您发布了多个名为搜索的字段。



只需更改侧栏中输入的名称修复这个错误。你也应该明确地对投入进行消毒(正如其他人注意到的那样)。

I am practicing with php mysql search results. The only problem I am getting is that the search isn't consistent in returning results.

Please visit:

weezy.co.uk/newresults.php

type in 'trainee' in the first search box at the top. Sometimes the results show sometimes they don't. I don't get it?

my HTML search box code is:

<form action="newresults.php" method="post" name="form">
<input type="text" id="search" name="search" 
size="30" value="" style="background-    color:white; border: 
solid 1px #ffffff; height: 30px; font-size:19px; font-family: 
HelveticaNeue-Light; font-weight: 1;
vertical-align:9px;color:#151515" 
onfocus="if(this.value == ''){this.value = 
'';this.style.color='#363D42'}" />
</div>
</div>
<div class="search">
<div class="search1">
<input type="text" 
id="searchterm" name="searchterm"  size="25" value="" style="background- 
color:white;  border: 
solid 1px #ffffff; height: 30px; font-size:19px; font-family: 
HelveticaNeue-Light; font-            weight: 1;
vertical-align:9px;color:#151515" 
onfocus="if(this.value == ''){this.value = 
'';this.style.color='#363D42'}" />
</form>

php code:

<?php

$conn = mysql_connect("", "", "");

if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}

{

$search = "%" . $_POST["search"] . "%";
$searchterm = "%" . $_POST["searchterm"] . "%";

}

if (!mysql_select_db("weezycouk_641290_db1")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}

$sql = "SELECT name,lastname,email 
    FROM   test_mysql
    WHERE  name LIKE '$search%' AND lastname LIKE '$searchterm%'";

$result = mysql_query($sql);

if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}

if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}


while ($row = mysql_fetch_assoc($result)) {
echo '<br>';
echo '<br>';
echo '<div class="data1">';
echo $row["name"];
echo '</div>';
echo '<br>';
echo '<div class="data2">';
echo $row["lastname"];
echo '</div>';
echo '<br>';
echo '<div class="data3">';
echo $row["email"];
echo '</div>';
}

mysql_free_result($result);

?>

Thanks guys!

James

解决方案

When your page loads with results, you also load a "Tags" sidebar with the question "Want the recruiters to find you?" The input boxes in that sidebar are filled in with "Enter name" and "Enter chosen industry." The "name" attribute on both those inputs is "search," so you are posting multiple fields named "search."

Just change the names on the inputs in your sidebar to fix this bug. You should definitely sanitize the inputs (as others have noted), too.

这篇关于我的搜索结果不一致?为什么是这样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆