I am trying to make an autocomplete form using an input (text) ... I used this way but I do not know if it will be fine ... I leave the code: (I have a patient table (id, code_pac, name, surname_paterno )
CONNECT.PHP
<?php
$hostname_strcn = "localhost";
$database_strcn = "basededatos";
$username_strcn = "usuario";
$password_strcn = "";
mysqli_connect($hostname_strcn, $username_strcn, $password_strcn) or
die(mysqli_error());
mysqli_select_db($database_strcn) or die(mysqli_error());
?>
INDEX.PHP
<?php
if (isset($_GET['action'])) {
include_once('connect.php');
$strsql = "SELECT * FROM paciente WHERE codigo_pac=".$_GET['codigo_pac'];
$rs = mysqli_query($strsql) or die(mysqli_error());
$row = mysqli_fetch_assoc($rs);
$total_rows = mysqli_num_rows($rs);
}
?>
<div>
<div class="form-group">
<label for="first-name">Ingrese el Código del Paciente</label>
<input type="text" class="form-control" id="codigo_pac" value="<?php echo($row['codigo_pac']);?>" name ="codigo_pac">
<input type="hidden" id="action" name="action" value="sent">
<input type="submit" id="btn_submit" value="Enviar">
</div>
</div>
<div class="form-group">
<label for="first-name">Nombres</label>
<input type="text" class="form-control" id="nom" name ="nom" value="<?php echo($row['nombre']); ?>">
</div>
<div class="form-group">
<label for="last-name">Apellido Paterno</label>
<input type="text" class="form-control" id="apat" name ="apat" value="<?php echo($row['apellido_paterno']); ?>">
</div>
AT THE TIME OF TESTING ... I get "Notice: Undefined variable: row in C: \ xampp \ htdocs \ cnsbol \ patientsearch.php on line" ... both in the code input and the two inputs of ( first and last name) ... I would appreciate your help please ... (THE IDEA IS TO MAKE A SELF-COMPLETED FORM) ... thanks