Php 搜索用户详细信息表单
我想知道是否有人能帮忙 我正在尝试组合一个表单,允许管理员通过用户的电子邮件地址搜索用户,并在表单上的相关文本字段中返回和插入“first”和“nam姓氏”值 我已经能够让“搜索”功能发挥作用,它检索到正确的结果。但是,我找不到将检索到的“first”和“姓氏”值插入表单上相关文本字段的方法 这是我整理的表格Php 搜索用户详细信息表单,php,mysql,html,Php,Mysql,Html,我想知道是否有人能帮忙 我正在尝试组合一个表单,允许管理员通过用户的电子邮件地址搜索用户,并在表单上的相关文本字段中返回和插入“first”和“nam姓氏”值 我已经能够让“搜索”功能发挥作用,它检索到正确的结果。但是,我找不到将检索到的“first”和“姓氏”值插入表单上相关文本字段的方法 这是我整理的表格 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1
<!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>
无标题文件
搜索:
I.尝试将它们放在$\u会话或$\u COOKIE中,并以尝试访问$\u COOKIE或$\u会话的形式
二、 我建议您使用jQuery调用此脚本并接收包含数据的JSON并填充输入…如果您将操作设置为action=“”,而不是search.php,并在HTML之前的页面顶部执行查询,您将能够像现在一样在正文中使用$row['forename'],等等(当然,除非使用正确的变量名)
否则,如果您将结果保留在该脚本中,我建议在脚本末尾添加以下内容:
<?
header("Location: originalpage.html?fn=".$row['forename']."&sn=".$row['surname']);
?>
并使用$\u GET['fn']和$\u GET['sn']将其放置在value=”“字段中。All,非常感谢您在这方面的帮助
经过进一步研究,我发现了一个示例,我可以对其进行更改,因此解决方案如下:
<?php
mysql_connect ("hostname","username","password") or die (mysql_error());
mysql_select_db ("databasename");
$emailaddress = $_POST['emailaddress'];
$sql = mysql_query("select * from userdetails where emailaddress like '$emailaddress'");
while ($row = mysql_fetch_array($sql)){
$forename = $row['forename'];
$surname = $row['surname'];
//we will echo these into the proper fields
}
?>
<html>
<head>
<title>Search the Database</title>
</head>
<body>
<form action="search.php" method="post">
Search: <input type="text" id="emailaddress" name="emailaddress"/><br />
First Name:<br/>
<input type="text" value="<?php echo $forename;?>" name="forename"/>
<br/>
Surname:<br/>
<input type="text" value="<?php echo $surname;?>" name="surname"/>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
为什么
<?php
mysql_connect ("hostname","username","password") or die (mysql_error());
mysql_select_db ("databasename");
$emailaddress = $_POST['emailaddress'];
$sql = mysql_query("select * from userdetails where emailaddress like '$emailaddress'");
while ($row = mysql_fetch_array($sql)){
$forename = $row['forename'];
$surname = $row['surname'];
//we will echo these into the proper fields
}
?>
<html>
<head>
<title>Search the Database</title>
</head>
<body>
<form action="search.php" method="post">
Search: <input type="text" id="emailaddress" name="emailaddress"/><br />
First Name:<br/>
<input type="text" value="<?php echo $forename;?>" name="forename"/>
<br/>
Surname:<br/>
<input type="text" value="<?php echo $surname;?>" name="surname"/>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>