我有一个动态的下拉搜索栏,通过在我的网页上的窗体内的数据库的成员进行搜索。要浏览这个网页,你必须先登录。当我在我的域名上建立网站时,一切都很好。然而,当我把我的文件转移到一个不同的域,并配置了一个相同的数据库,一切工作完美,除了我的动态搜索在这种形式。如果我在搜索中输入我的名字(有时是奇怪的不同的名字与工作),一切都很好,但如果我输入其他人,它似乎应该留在页面上,但它将我注销并重新加载登录表单在其他一切之上,包括我的表单,我正在输入。我使用jQuery .post()使搜索动态。我将在
下面提供代码index . php
<script>
// this is the jQuery function used to post to the search document on key up
function searchUserQ(){
var searchTxt = $("input[name='userSearch']").val();
console.log(searchTxt);
if (searchTxt != '') {
$.post("includes/search.php", {searchVal:searchTxt},
function(output){
$("#userResults").html(output);
});
}
}
</script>
<h1 class="editUser">Edit User</h1>
<form class="editUser" action="index.php" method="post">
<h1>Search For Employee</h1>
<input type="text" name="userSearch" id="userSearch" placeholder="Search For Employee By First Name" onkeyup="searchUserQ();" />
<submit type="submit" />
<div id="userResults">
</div>
</form>
Search.php
<?php
// Connect To Secure Login
$cfgProgDir = '../phpSecurePages/';
include($cfgProgDir . "secure.php");
//These are the includes needed to make the php page run
// this file connects to the database
include("connect.inc.php");
if(isset($_POST['searchVal'])){
// turn that the user searched into a varible
$searchQ = $_POST['searchVal'];
// delete any symbols for security
$searchQ = preg_replace("#[^0-9a-z]#i", "", $searchQ);
$output = "";
$link = "";
$searchArray = array();
$searchIndex = 0;
// Search through these columns inside the main database
$userSearchQuery = mysql_query("SELECT * FROM dealerEmployees WHERE
firstName LIKE '%$searchQ%'
");
// count the number of results
$userCount = mysql_num_rows($userSearchQuery);
if($userCount == 0){
// $output = "There Were No Search Results";
}else{
while($row = mysql_fetch_array($userSearchQuery)){
// define dynamic varibles for each loop iteration
$id = $row['id'];
$firstName = $row['firstName'];
$lastName = $row['lastName'];
$address = $row['address'];
$phone = $row['phone'];
$email = $row['email'];
$password = $row['password'];
$permission = $row['permission'];
$photo = "images/" . $row['profilePhoto'];
$output .= "<li><div class='employeeSearch' style='"background: url('$photo'); width: 75px; height: 75px'"></div><h6>" . $firstName . "</h6>" . " " . "<h6>" . $lastName . "</h6><a href='#' class='employee' data-firstName='$firstName' data-lastName='$lastName' data-address='$address' data-phone='$phone' data-email='$email' data-password='$password' data-permission='$permission' data-id='$id'>Select Employee</a></li>";
}
}
}
echo $output;
你能试试吗?
> "SELECT id, firstName, lastName, address, phone, email, password,
> permission profilePhone FROM dealerEmployees WHERE
> firstName = '".$searchQ."' Limit 1"
可能类似的条件给出了不止一个结果。
也许你可以做一个select count(id)作为id从dealerEmployees where firstName = '".$searchQ。',并使用if子句检查计数。可能问题是有太多用户使用相同的firstName
所以经过一些测试,我发现发生了什么。当搜索加载搜索结果时,它会将会话中的密码变量更改为搜索中出现的用户的密码,因为两个变量具有相同的名称,因此我所需要做的就是将搜索结果中密码变量的var名称更改为与会话密码不同。
感谢所有的帮助!!