From some very sound guidance from this forum I've put together a php script that allows an administrator, via an html form, to search for member records using the email address as the search criteria and it works fine.
The problem I have is populating the first and surname fields in the html fields upon the search being complete. Instead of filling out the relevant form fields, the results appear on a separate web page. I'm sure the answer is really simple, but I've been trying to get this to work over the last couple of days without success.
I've posted the php script and html form below.
Could someone perhaps take a look at this please and let me know where I'm going wrong.
Many thanks
PHP Script
<?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 Form
<!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>
Not sure If I understand...
Do you want to auto-fill the names after the email? If so, you have to use AJAX to call a PHP page.
With jQuery you can do that easily.
精彩评论