从这个论坛的一些非常合理的指导我已经整理了一个php脚本,允许管理员通过html表单使用电子邮件地址作为搜索条件搜索成员记录,并且它工作正常。
我遇到的问题是在搜索完成后填充html字段中的first和surname字段。结果显示在单独的网页上,而不是填写相关的表单字段。我确信答案非常简单,但我一直试图在过去的几天里使用它而没有成功。
我在下面发布了php脚本和html表单。
有人可能请看看这个,让我知道我哪里出错了。
非常感谢
PHP脚本
<?php
require("phpfile.php");
// Opens a connection to a MySQL server
$connection=mysql_connect ("hostname", $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$email = $_POST['email'];
$result = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%$email%'");
while($row = mysql_fetch_array($result))
{
echo $row['forename'];
echo $row['surname'];
echo "<br />";
}
?>
HTML表单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Map!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script src="js/gen_validatorv4.js" type="text/javascript"></script>
</head>
<body>
<h1>Member Password Reset </h1>
<form name="memberpasswordreset" id="memberpasswordreset" method="post" action="search.php">
<div class="title1">
<h2>Member Details </h2>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="26%" height="25"><strong>Email Address </strong></td>
<td width="4%"> </td>
<td width="70%"><input name="email" type="email" id="email" size="50" /></td>
</tr>
<tr>
<td height="25"><strong>Confirm Email</strong></td>
<td> </td>
<td><input name="conf_email" type="email" id="conf_email" size="50" /></td>
</tr>
<tr>
<td height="25"><label>
<input type="submit" name="Submit" value="search" />
</label></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"><strong>First Name </strong></td>
<td> </td>
<td><input name="fname" type="text" id="fname" size="30" value="<?php echo $forename; ?>" /> </td>
</tr>
<tr>
<td height="25"><strong>Last Name </strong></td>
<td> </td>
<td><input name="lname" type="text" id="lname" size="30" value="<?php echo $surname; ?>" /> </td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"><strong>Password</strong></td>
<td> </td>
<td><input name="pass" type="password" id="pass" size="30" /></td>
</tr>
<tr>
<td height="25"><strong>Confirm Password </strong></td>
<td> </td>
<td><input name="conf_pass" type="password" id="conf_pass" size="30" /></td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"><strong>Password Hint </strong></td>
<td> </td>
<td><input name="hint" type="text" id="hint" size="30" /></td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
// Code for validating the form
var frmvalidator = new Validator("memberpasswordreset");
frmvalidator.addValidation("email","req","Please enter the users email address");
frmvalidator.addValidation("email","email","Please enter a valid email address");
frmvalidator.addValidation("conf_email","eqelmnt=email", "The confirmed email address is not the same as the email address");
</script>
</body>
</html>
答案 0 :(得分:0)
不确定如果我理解......
您想在电子邮件后自动填写姓名吗?如果是这样,你必须使用AJAX来调用PHP页面。
使用jQuery,您可以轻松完成。