Receive information from the database and send to the form field

Asked

Viewed 1,001 times

2

Good morning. I was wondering how do I get the information I want sent inside the input(Client name), because I did 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>
  • Where do you want to put the name? in input value? This PHP and HTML code are in the same PHP file?

  • 1

    Forehead <input type="text" name="nome" size="80" value="<?php echo $cliente->getNome(); ?>" />

  • Opa , sorry for the delay, I had left. But I’ve returned

  • They’re all in the same file, yes, I want to put in input value

  • 1

    Friend, it worked. Thank you very much! If you want to put as answer, I will mark as right .

2 answers

2

You must echo the attribute value of your input with calling the desired dice.

Script for 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>

2


To insert the variable value into the HTML you can concatenate in case you are doing echo 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  />

Browser other questions tagged

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