我想知道是否有人可以帮助我。
我正在尝试创建一个表单,用于从mySQL数据库中搜索会员详细信息,检索结果以便它们出现在预定的文本框中,并进行更新以发送回数据库。
我正在使用以下代码:
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'];
$sql = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%$emailaddress%'");
while($row = mysql_fetch_array($sql))
{
echo $row['forename'];
echo $row['surname'];
echo "<br />";
}
?>
HTML表单
<!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 $forename; ?>" />
</label>
</p>
<p>
<input name="surname" type="text" id="surname" value="<?php echo $surname; ?>" />
</p>
<p> </p>
</form>
</body>
</html>
我正在使用电子邮件地址搜索所需的记录,但我的问题是检索到了所有记录而不是我输入详细信息的那个记录,并且结果没有出现在表单的名字和姓氏字段中。
也许有人可以告诉我我做错了什么
顺祝商祺