php 如何从数据库 MySQL 中检索数据并在文本框中显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28122922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:42:18  来源:igfitidea点击:

How to retrieve data from database MySQL and display in text box

php

提问by North22

I'm trying to display the data from the database into the text box form like <input type="text" class="form-control" name="user_id" data-mask="999-99999" disabled value="<?php echo $row['user_id']; ?>" >but the data does'nt show up in the form.

我试图将数据库中的数据显示到文本框表单中,<input type="text" class="form-control" name="user_id" data-mask="999-99999" disabled value="<?php echo $row['user_id']; ?>" >但数据没有显示在表单中。

Heres my query

这是我的查询

$query = "SELECT * from admin where username = '{$_SESSION['login_user']}'";
            $result = mysqli_query($conn,$query);
            while($row=mysqli_fetch_assoc($result))

When I tried this method the data has been show up using table tags, but not in the text box field.

当我尝试此方法时,数据已使用表格标签显示,但未显示在文本框字段中。

    $query = "SELECT * from admin where username = '{$_SESSION['login_user']}'";
    $result = mysqli_query($conn,$query);
    while($row=mysqli_fetch_assoc($result))
    {
        echo"<tr>";
        echo"<td>";?> <?php echo $row['user_id']; ?>  <?php echo "</td>";

        echo"</tr>";
    }
    echo"</table>";

回答by Jun Rikson

Please learn more about HTML

请了解有关 HTML 的更多信息

while($row=mysqli_fetch_assoc($result))
    {
        echo '<input type="text" value='.$row['user_id'].'><br/>';
    }

回答by Jun Rikson

$query = "SELECT * from admin where username = '{$_SESSION['login_user']}'";
$result = mysqli_query($conn,$query);
while($row=mysqli_fetch_assoc($result))
{
    echo"<tr>";
    echo"<td><input type=\"text\" name=\"user_id\" value=\".$row['user_id']."\"></td>";
    echo"</tr>";
}
echo"</table>";

Its not the best answer but I modified your code so the value is in the text box itself. If theres only one record in the database matching your query, then you're all set.

它不是最佳答案,但我修改了您的代码,因此该值位于文本框中。如果数据库中只有一条记录与您的查询匹配,那么您就大功告成了。