Tona09 de Noviembre del 2003
PreguntaSegui el tutorial de PHP y MySQL y en la parte donde se hace una consulta no me registra la vaiable, la form es:
<html>
<head>
<title>Title here!</title>
</head>
<body>
<form method="POST" action="http://cassual.com/php/buscador.php3">
<strong>Nombre o Apellido:</strong>
<input name="T1" type="text" size="20">
<br><br>
<input type="submit" value="Buscar" name="buscar">
</form>
</body>
</html>
y el php es:
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php
if (!isset($nombre)){
echo "Debe especificar una cadena a bucar";
echo "</html></body> n";
exit;
}
$link = mysql_connect("localhost", "tona");
mysql_select_db("test", $link);
$result = mysql_query("SELECT * FROM directorio WHERE nombre LIKE '%$buscar%' or apellido 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["nombre"]."</td> n";
echo "<td>".$row["apellido"]."</td> n";
echo "<td>".$row["tel_of"]."</td> n";
echo "<td>".$row["tel_casa"]."</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>
<html>
<head>
<title>Title here!</title>
</head>
<body>
<form method="POST" action="http://cassual.com/php/buscador.php3">
<strong>Nombre o Apellido:</strong>
<input name="T1" type="text" size="20">
<br><br>
<input type="submit" value="Buscar" name="buscar">
</form>
</body>
</html>
y el php es:
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php
if (!isset($nombre)){
echo "Debe especificar una cadena a bucar";
echo "</html></body> n";
exit;
}
$link = mysql_connect("localhost", "tona");
mysql_select_db("test", $link);
$result = mysql_query("SELECT * FROM directorio WHERE nombre LIKE '%$buscar%' or apellido 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["nombre"]."</td> n";
echo "<td>".$row["apellido"]."</td> n";
echo "<td>".$row["tel_of"]."</td> n";
echo "<td>".$row["tel_casa"]."</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>
