How to remove the error message that comes out in the input - php

3

Hello everyone I have a small problem with the input, I get an error message in the input, I've been looking to resolve but I have not obtained results.

I attached an image of the error that shows me.

Here I attach the code.

  <?php
 include 'conexion.php';
  ?>

 <form action="buscador.php" method="get">
 <input type="text" name="palabra" placeholder="buscar aqui.." value="<?php  echo ($_GET["palabra"]); ?>"  />
  <input type="submit" name="buscador" value="Buscar" id="buscar" />

 <style type="text/css">
   #buscar{
    display: none;
         }
</style>

</form>
<?php 

if(isset($_GET['buscador'])){

$buscar = $_GET['palabra'];

if (empty($buscar)){
echo "No se ha ingresado ninguna palabra";
}
else
{

$sql = "SELECT * FROM registro WHERE nombre LIKE '%$buscar%'";
$result = $conexion->query($sql);

$total = mysqli_num_rows($result);

if ($row = mysqli_fetch_array($result)) {

echo "Resultados para: $buscar";
?>
<br>
<?php
echo "Total de resultados: $total";

do {
 ?>
<br>
<br>
 <a href="<?php echo $row['link'] ?>">(nombre: <?php echo $row['nombre']; ?>)
 </a>

<?php
}
while ($row = mysqli_fetch_array($result));
}
else
{
echo "No se encontraron resultados para: $buscar";
}
}
}
?>
    
asked by kyle 30.05.2017 в 19:00
source

1 answer

1

What happens is that when you enter the page you still do not send any data for GET and there you mark the error. What you should do is validate if the variable is being sent with the function isset and if it is commanded to do the echo , remaining as follows:

<input type="text" name="palabra" placeholder="buscar aqui.." value="<?php if (isset($_GET["palabra"])) {  echo $_GET["palabra"]; }?>"  />
    
answered by 30.05.2017 / 19:05
source