我正在使用 buddypress 开发一个 wordpress 网站。所以,我正在创建一个页面,您可以在其中查看成员并使用数据库搜索他们:wp_users。如果我将它作为 php 添加到 wp 页面时,它会正常显示,但单击提交时会出现 404 错误。
这是代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Search Contacts</title>
<style type="text/css">
#spacer {
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
}
</style>
</head>
<p><body>
<p> </p>
<form method="post" action="" id="searchform">
<p>
<input name="name" type="text">
<input type="submit" name="submit" value="Søk">
</p>
<p>Tips: du kan søke etter adresse, navn og e-post.</p>
</form>
<table width="600">
<tr>
<th width="200" height="50">Navn</th>
<th width="200"> </th>
<th width="200">E-post adresse</th>
</tr>
<?php
/* Change next two lines if using online*/
$db="skynnaks_skyn";
$link = mysql_connect('localhost', 'skynnaks_skyn', '*password*');
if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM wp_users" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
if ($result) {
while ($row = mysql_fetch_array($result)) {
$_SESSION['id']=$row['id'];
#echo "<tr><a href='#'>".$row['display_name']."</a>";
echo "<td><a href="."/members/".$row['user_nicename']."/profile/>".$row['display_name']."</a></td>";
#echo "<a href=" '.$row['id'].'>Bruker: ".$row['user_url']."</a>";
echo "<td><a href=".$row['user_url'].">".$row['user_url']."</a></td>";
echo "<td><a href=".'mailto:'.$row['user_email'].">".$row['user_email']."</a></td></tr>";
}
}
?>
</table>
<div id="spacer">
<?php
if(isset($_POST['submit'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
//connect to the database
$db=mysql_connect ("localhost", "skynnaks_skyn", "*password*") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("skynnaks_skyn");
//-query the database table
$sql="SELECT ID, user_login, user_nicename FROM wp_users WHERE user_login LIKE '%" . $name . "%' OR user_nicename LIKE '%" . $name ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$loginName =$row['user_login'];
$niceName=$row['user_nicename'];
$ID=$row['ID'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href="."/members/".$loginName."/profile/>".$niceName."</a>" ;
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
?>
</div>
<p> </p>
</body>
</html>
</p>
PS:由于 buddypress 插件,我不能使用默认的永久链接。而且我知道 buddypress 带有会员搜索功能,但我已经安装了挪威语语言包,但它不适用于 buddypress 中的会员搜索。
谢谢您的帮助 :)