Php:选择mysql表元素时自动完成输入 [英] Php: autocomplete inputs when mysql table element selected

查看:43
本文介绍了Php:选择mysql表元素时自动完成输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个简单的应用程序来发送确认电子邮件。我有一个包含4列的MySQL表:id,user_email,user_name和user_track。该表单包含一个选择框,显示存储的所有user_email和两个文本输入,当选择电子邮件时应该自动完成。



我尝试过:



我尝试了以下内容,但它只是回显了user_track和user_name的所有条目。

I'm building a simple app to send confirmation emails. I have a MySQL table with 4 columns: id, user_email, user_name and user_track. The form consists of a selectbox that shows all the user_email stored and two text inputs that should be autocompleted when an email is selected.

What I have tried:

I have tried the following, but it just echo's all the entries for user_track and user_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();
?>

推荐答案

servername =localhost;
servername = "localhost";


username = root;
username = "root";


password =;
password = "";


这篇关于Php:选择mysql表元素时自动完成输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆