gpt4 book ai didi

php - 根据用户id制作一个搜索按钮

转载 作者:行者123 更新时间:2023-11-29 12:45:19 26 4
gpt4 key购买 nike

我想进行搜索。当我在文本框中输入用户 ID 并按提交按钮时,会出现用户数据。我要怎么做呢?我知道这个编码有点错误。顺便说一句,我是管理员,想找到用户。

<?php
include 'config1.php';
$query = "SELECT * FROM login WHERE userid LIKE '%$searchTerm%'"
$result = mysql_query($query);
echo "<table height = '30%'border='1'>";

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<tr>";
echo "<td width='5%'><b>USER ID:</b> {$row['userid']} </td>";
echo "<td width='5%'><b>USER NAME :</b> {$row['username']} </td>";
echo "<td width='5%'><b>USER EMAIL:</b> {$row['useremail']} </td>";
echo "<td width='5%'><b>USER DIVISION:</b> {$row['userdiv']} </td>";
echo "<td width='5%'><b>USER DEPARTMENT:</b> {$row['userdepartment']} </td>";
}
echo"</table>";
?>

最佳答案

取自 your comment

when i run this on website it say Parse error: syntax error, unexpected '$result' (T_VARIABLE) in C:\xampp\htdocs\viewAdmin.php on line 41

此行中缺少分号:

$query = "SELECT * FROM login WHERE userid LIKE '%$searchTerm%'"
^

$query = "SELECT * FROM login WHERE userid LIKE '%$searchTerm%'";

另外,使用 $searchTerm例如,您需要使用带有名为“搜索”的输入的表单。 <input type = "text" name = "search">然后做:

$searchTerm = $_POST['search'];

使用 POST 表单方法。

<form method = "post" action = "your_SQL_file.php">

Search: <input type = "text" name = "search">

<input type = "submit" name = "submit" value = "Search">

</form>
<小时/>
<?php 
include 'config1.php';
$searchTerm = $_POST['search'];
$query = "SELECT * FROM login WHERE userid LIKE '%$searchTerm%'";

...
<小时/>

编辑:(全部在一个文件中)

<form method = "post" action = "">

Search: <input type = "text" name = "search">

<input type = "submit" name = "submit" value = "Search">

</form>


<?php
include 'config1.php';

if(isset($_POST['submit'])){

$searchTerm = mysql_real_escape_string($_POST['search']);

$query = "SELECT * FROM login WHERE userid LIKE '%$searchTerm%'";
$result = mysql_query($query);

echo "<table height = '30%'border='1'>";

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<tr>";
echo "<td width='5%'><b>USER ID:</b> {$row['userid']} </td>";
echo "<td width='5%'><b>USER NAME :</b> {$row['username']} </td>";
echo "<td width='5%'><b>USER EMAIL:</b> {$row['useremail']} </td>";
echo "<td width='5%'><b>USER DIVISION:</b> {$row['userdiv']} </td>";
echo "<td width='5%'><b>USER DEPARTMENT:</b> {$row['userdepartment']} </td>";
}
echo"</table>";

} // brace for submit isset
?>

关于php - 根据用户id制作一个搜索按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25533042/

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