I wonder whether someone may be able to help please.
I’m trying to put together a form that allows an administrator to search for users via their email address returning and inserting the ‘first’ and ‘surname’ values in the associated text fields on the form.
I’ve been able to get the ‘search’ functionality to work and it retrieves the correct results. However I can’t find a way of inserting the retrieved ‘first’and ‘surname’ values into the pertinent text fields on my form.
This is the form which I’ve put together
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="search.php" method="post">
<p>Search:
<input name="emailaddress" type="text" id="emailaddress" />
<br />
<input type="submit" name="submit" value="Submit" />
</p>
<p>
<label>
<input name="forename" type="text" id="forename" value="<?php echo isset($forename)?>" />
</label>
</p>
<p>
<input name="surname" type="text" id="surname" value="<?php echo isset($surname)?>" />
</p>
<p> </p>
</form>
</body>
</html>
and the following is the PHP script that I’m using to retrieve the users information.
<?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());
}
//<form action="phpfile.php" method="post">
//<input name="emailaddress" type="text" id="emailaddress" />
// --> $_POST['emailaddress']
$emailaddress_sql = mysql_real_escape_string($_POST['emailaddress'], $connection);
$sql = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%{$emailaddress_sql}%'");
while( false!=($row = mysql_fetch_array($sql)) ) {
echo
$row['forename'], ' ',
$row['surname'],
"<br />\n";
}
I just wondered whether someone could perhaps take a look a this please and let me know where I’m going wrong.
Many thanks
All, many thanks for your help on this.
After some more research, I found an example which I was able to make changes to, so the solution is as follows: