North22
North22

Reputation: 41

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

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.

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

Upvotes: 0

Views: 28957

Answers (2)

Jun Rikson
Jun Rikson

Reputation: 1884

Please learn more about HTML

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

Upvotes: 1

user4064342
user4064342

Reputation:

$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.

Upvotes: 0

Related Questions