Tengo 3 campos id,nombre,costo el cual me debe buscar por cualquier de los datos ingresados, pero no me busca nada
Buscar.html
Código HTML:
<html> <body> <form id="form1" name="form1" method="POST" action="buscador.php"> <p> <label for="cliente">Numero Id:</label> <input type="text" name="id" id="id" /> <label for="nombre"><br /> Nombre Nombre:</label> <input type="text" name="nombre" id="nombre" /> <label for="agente"><br /> Nombre Costo:</label> <input type="text" name="costo" id="costo" /> <label for="zona"><br /> </label> </p> <p> <input type="submit" name="buscar" id="buscar" value="Buscar" /> </p> </form> </body> </html>
Código PHP:
<?php
$conectar=mysql_connect("localhost","root","vertrigo");
$selecciona=mysql_select_db("ferreteria");
$id= $_POST['id'];
$nombre= $_POST['nombre'];
$costo= $_POST['costo'];
$sql='Select id,nombre,costo from items';
if($_POST['id']!=""){
$sql=' and id like "%'.$_POST['id'].'%"';
}
if($_POST['nombre']!=""){
$sql=' and nombre like "%'.$_POST['nombre'].'%"';
}
if($_POST['costo']!=""){
$sql=' and costo like "%'.$_POST['costo'].'%"';
}
$ejecuta=mysql_query($sql);
while($filas=mysql_fetch_array($ejecuta)){
print $filas ['id'].'<br/>';
print $filas ['nombre'].'<br/>';
print $filas ['costo'].'<br/>';
}
?>
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\Archivos de programa\VertrigoServ\www\ferreteriah\buscador.php on line 34