Estoy haciendo una mínima web para una práctica, pero al querer ponerle un buscador, me sale siempre el siguiente error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C: \Servidor\WEB\buscador.php on line 13
¡ No se ha encontrado ningún registro !
Mi código php es el siguiente, está en el archivo buscador.php:
Código PHP:
<html>
<body>
<?php
if (isset($buscar)){
echo "Debe especificar una cadena a buscar";
echo "</html></body> \n";
exit;
}
$link = mysql_connect("localhost", "kalixe985","garzimba985");
mysql_select_db("mydb", $link);
$result = mysql_query("SELECT * FROM agenda WHERE nombre LIKE '%$buscar%' ORDER BY nombre", $link);
if ($row = mysql_fetch_array($result)){
echo "<table border = '1'> \n";
//Mostramos los nombres de las tablas
echo "<tr> \n";
while ($field = mysql_fetch_field($result)){
echo "<td>$field->name</td> \n";
}
echo "</tr> \n";
do {
echo "<tr> \n";
echo "<td>".$row["id"]."</td> \n";
echo "<td>".$row["nombre"]."</td> \n";
echo "<td>".$row["direccion"]."</td> \n";
echo "<td>".$row["telefono"]."</td> \n";
echo "<td><a href='mailto:".$row["email"]."'>".$row["email"]."</a></td> \n";
echo "</tr> \n";
} while ($row = mysql_fetch_array($result));
echo "</table> \n";
} else {
echo "¡ No se ha encontrado ningún registro !";
}
?>
</body>
</html>
Código HTML:
<html> <body> <form method="POST" action="http ://localhost/buscador.php"> <strong>Palabra clave:</strong> <input type="text" name="T1" size="20"><br><br> <input type="submit" value="Buscar" name="$buscar"> </form> </body> </html>