Ahora si utilizo un codigo en el cual el formulario y el buscador esten un una misma pagina de php, entonces si hace la busqueda.
Quisiera saber si alguno tiene algun codigo que me pueda servir.
Ademas porque si uno oprime el boton "enter" no hace la busqueda, tengo que por fuerza oprimir el boton de busqueda?
Este el codigo que baje de internet:
Cita:
<form method="POST" action="buscador.php">
<strong>Palabra clave:</strong> <input type="text" name="T1" size="20"><br><br>
<input type="submit" value="Buscar" name="buscar">
</form>
<strong>Palabra clave:</strong> <input type="text" name="T1" size="20"><br><br>
<input type="submit" value="Buscar" name="buscar">
</form>
Cita:
Espero que me puedan ayudar <?php
if (!isset($_POST['buscar'])){
echo "Debe especificar una cadena a bucar";
echo "</html></body> \n";
exit;
}
$link = mysql_connect("localhost", "root" , "");
mysql_select_db("mydb", $link);
$result = mysql_query("SELECT * FROM agenda WHERE nombre LIKE '%buscar%' ", $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 !";
}
?>
if (!isset($_POST['buscar'])){
echo "Debe especificar una cadena a bucar";
echo "</html></body> \n";
exit;
}
$link = mysql_connect("localhost", "root" , "");
mysql_select_db("mydb", $link);
$result = mysql_query("SELECT * FROM agenda WHERE nombre LIKE '%buscar%' ", $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 !";
}
?>