gpt4 book ai didi

php - 搜索用户详细信息表

转载 作者:行者123 更新时间:2023-11-29 14:37:10 24 4
gpt4 key购买 nike

我想知道是否有人可以提供帮助。

我正在尝试构建一个表单,允许管理员通过电子邮件地址搜索用户,并在表单上的关联文本字段中返回并插入“名字”和“姓氏”值。

我已经能够使用“搜索”功能并检索正确的结果。但是,我找不到将检索到的“名字”和“姓氏”值插入表单上的相关文本字段的方法。

这是我整理的表格

<!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>&nbsp; </p>
</form>
</body>
</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());
}

//<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";
}

我只是想知道是否有人可以看一下这个并让我知道我哪里出错了。

非常感谢

最佳答案

非常感谢您对此的帮助。

经过一番研究,我找到了一个可以进行更改的示例,因此解决方案如下:

<?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 - 搜索用户详细信息表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8790733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com