input in PHP with the fields filled in

1

PHP script.

My database has 3 fields:

  

id, name, phone.

I need to update the data for 1 record.

On the first page, I request, by an input, the name of the record to change, and a "Search" button to locate the record to be changed.

On the second page I put the 2 fields for editing:

$nome_g1 = isset($_GET["nome"])?$_GET["nome"]:"";
$arma1   = isset($_GET["telefone"  ])?$_GET["telefone"  ]:"";

I would like the fields to already be populated with the data of the selected record.

Example:

First page I typed "Antonio", and the script found the record with the name "Antonio" and Phone "99999.9999".

2nd page:

  

Name ...: [Antônio]

     

Phone: [99999.9999]

     

Button: [refresh]

The question is: how to appear the data in the fields as soon as it enters the second page, before typing, ie in the line of "input"

    
asked by anonymous 30.07.2016 / 14:49

1 answer

1

Just by a echo in PHP returning the value in the field value :

If it's in the HTML part

Nome: <input name="nome" value="<?php echo htmlentities( $nome ); ?>">

or in the PHP part:

echo 'Nome: <input name="nome" value="'.htmlentities( $nome ).'">';

For fields like select :

<select name="estado">
   <option value="SP"<?php echo $estado=="SP"?' selected':''; ?>>

Same thing for radio and checkbox , only change the selected by the appropriate HTML attribute.

Obviously if you use multiple options in select, a separate function for this may be more practical, but just understand the logic above.

    
30.07.2016 / 15:02