gpt4 book ai didi

PHP:选择 MySQL 表元素时自动完成输入

转载 作者:行者123 更新时间:2023-11-29 16:03:54 25 4
gpt4 key购买 nike

我正在构建一个简单的应用程序来发送确认电子邮件。我有一个包含 4 列的 MySQL 表:iduser_emailuser_nameuser_track。该表单由一个显示所有存储的 user_email 的选择框和两个在选择电子邮件时应自动完成的文本输入组成。我已尝试以下操作,但它只是 echouser_trackuser_name 的所有条目。

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, user_email, user_name, user_track FROM demo_data ORDER BY id DESC";
$option = '';
$artist = '';
$track = '';
$result = $conn->query($sql);

while($row = $result->fetch_assoc()){
$option .= '<option value = "'.$row['user_email'].'">'.$row['user_email'].'</option>';
$track .= '<input type="text" name="track" required value = "'.$row['user_track'].'">';
$artist .= '<input type="text" name="artist" required value = "'.$row['user_name'].'">';
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Admin</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="main">
<h1>Accepted demo</h1>
<form action="demo.php" method="post">
<select name="select">
<?php echo $option; ?>
</select><br><br>
<?php echo $track; ?><br><br>
<?php echo $artist; ?><br><br>
<input type="date" name="date" placeholder="Release Date" required>
<br><br>
<input style="margin-top:10px;" class="btn" type="submit" value="Send email">
</form>
</body>
</html>
<?php
$conn->close();
?>

最佳答案

更新来自

$sql = "SELECT id, user_email, user_name, user_track FROM demo_data ORDER BY id DESC";

$sql = "SELECT id, user_email, user_name, user_track FROM demo_data WHERE user_email='".$_POST['selected_user_email']."' ORDER BY id DESC";

其中 selected_user_email 是要发布的输入字段的名称

关于PHP:选择 MySQL 表元素时自动完成输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55920348/

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