gpt4 book ai didi

javascript - jQuery $.post() 在按下按键时将我注销

转载 作者:行者123 更新时间:2023-11-28 07:11:20 25 4
gpt4 key购买 nike

我有一个动态下拉搜索栏,它可以搜索网页上表单内的数据库成员。为了查看该网页,您必须先登录。当我在我的域上构建网站时,一切正常。然而,当我将文件传输到不同的域并使用相同的数据库对其进行配置时,除了这种形式的动态搜索之外,一切都很完美。如果我在搜索中输入我的名字(有时与工作不同的奇怪名称),一切都会正常,但如果我输入其他人,它似乎会保留在页面上,但它会将我注销并重新加载顶部的登录表单其他一切,包括我正在打字的表格。我正在使用 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>

搜索.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"

也许类似的条件会给出超过 1 个结果。

关于javascript - jQuery $.post() 在按下按键时将我注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31281620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com