Receive information from the database and send it to the form field

2

Good morning. I wanted to know how I can get the information I want to be sent into input (Client Name), because I made the select and the information was not placed in the form field, it was on top. Follow my code below.

PHP

<body>

        <?php
        include_once '../DAO/Connect.php';
        include_once '../model/Cliente.php';

        $conexao = new Conexao();
        $cliente = new Cliente();
        $cliente = $conexao->selectCliente("_ID=" . '10');

        $cliente->getNome();
        echo $cliente->getNome(); ?>

HTML

<form action="#" method="get">  
            <label>Nome Cliente</label><br />
            <input type="text" name="nome" size="80" /><br  />

            <label>Nome Fantasia</label><br />
            <input type="text" name="nome-fantasia" size="80"  /><br />

            <div class="ao-lado">
                <label>CNPJ/CPF</label><br/>
                <input type="text" name="cpf" size="37" />
            </div>
        </form>
    
asked by anonymous 07.07.2015 / 14:18

2 answers

2

To insert the value of the variable inside the HTML you can concatenate in case you are doing echo of HTML, or in your case use echo of PHP within HTML:

<label>Nome Cliente</label><br />
<input type="text" name="nome" size="80" value="<?php echo $cliente->getNome(); ?>" /><br  />
    
07.07.2015 / 15:05
2

You should echo the value attribute of your input with calling the desired data.

Script example:

<form action="#" method="get">  
    <label>Nome Cliente</label><br />
    <input type="text" name="nome" size="80" value="<?php echo $cliente->getNome(); ?>" /><br  />

    <label>Nome Fantasia</label><br />
    <input type="text" name="nome-fantasia" size="80" value="<?php echo $cliente->getNomeFantasia(); ?>" /><br />

    <div class="ao-lado">
        <label>CNPJ/CPF</label><br />
        <input type="text" name="cpf" size="37" value="<?php echo $cliente->getCpf(); ?>" />
    </div>
</form>
    
07.07.2015 / 14:57