Popular form with database data

Asked

Viewed 28 times

2

I need to populate a form when the page loads, I tried to search with php and store it in an array and other ways ( some are commented), but there is no error, just no information appears. Like I’m doing:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        .container{
            max-width:600px;
            width:100%;
        }
        body{
            background:#ecf0f1;
        }
    </style>
    <?php
    require 'db.php';
    $iduser = $_POST['iduser'];
    $result = mysqli_query($conn,"SELECT * FROM tb_usuarios WHERE user_id='$iduser'");
    $row = mysqli_fetch_array($result);
    /*global $result_array;
    //$result_array = array();
    while($row = mysqli_fetch_assoc($result))
    {
        $result_array['user_nome'] = $row['user_nome'];
        $result_array['user_email'] = $row['user_email'];
        $result_array['user_end_rua'] = $row['user_end_rua'];
        $result_array['user_end_bairro'] = $row['user_end_bairro'];
        $result_array['user_end_numero'] = $row['user_end_numero'];
        $result_array['user_tel'] = $row['user_tel'];
        $result_array['user_cpf'] = $row['user_cpf'];

    }*/
    //$row = mysqli_fetch_array($result);
    //echo  $result_array['1'];
    ?>
    <title>Alterar Dados</title>
</head>
<body>
<div class="container" align="center">
    <img src="image/logo.fw.png" style="margin-top:25px;margin-bottom:25px" width="150" height="59" alt="logo">
    <div class="panel panel-default">
        <div class="panel-heading">Atualize seus dados</div>
        <div class="panel-body">
            <form action="php/cadastro.php" method="post">
                <div name="login">
                    <div class="input-group">
                        <span class="input-group-addon">Nome</span>
                        <input id="nome" type="text" class="form-control" name="user_nome" value="<?php echo $row['user_nome']; ?>" disabled>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">Email</span>
                        <input id="email" type="email" class="form-control" name="user_email"  value="<?php $row['user_email']; ?>" required >

                    <input type="hidden" name="user_nivel" value="0">

                    <div style="margin-top:12px">
                        <input type="reset" class="btn btn-warning pull-left" value="Limpar"/>
                        <input type="submit" class="btn btn-success pull-right"
                               style="padding-left:25px;padding-right:25px;" value="Cadastrar"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
  • 2

    The data is coming correctly to $row? Try to give a print_r($row) just to see...

  • @nunks.lol put this print under the Row and showed nothing

  • I lie, appear 1

  • Actually, I wasn’t returning anything from the database, I wasn’t taking the $_POST with the iduser, now this

  • And put yourself echo mysqli_error($conn)?

  • the connection this Ok, the problem was the iduser, who was not picking up, missed an echo there on the other page that has the passing post form

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.