0

ok look, the form is simple, it is post ID or description of the item, who should I throw a box with its own id, description and quantity.

here is the form:

<form method="post" action="buscarepuestos.php">
                        < label> Numero  o Descripción del Repuesto</label>
                        <input name="palabra" placeholder="Escriba Aquí">
    <input id="submit" name="buscar" type="submit" value="Buscar">
                    </form>

and now "buscarepuestos.php"

<?php

if ($_POST['buscar'])
{
// Tomamos el valor ingresado
$buscar = $_POST['palabra'];

// Si está vacío, lo informamos, sino realizamos la búsqueda
if(empty($buscar))
{
echo "No se ha ingresado una cadena a buscar";
}else{

//Conexión a la base de datos
$servidor = "localhost"; //Nombre del servidor
$usuario = "root"; //Nombre de usuario en tu servidor
$password = "1234"; //Contraseña del usuario
$base = "db_maquinas"; //Nombre de la BD
$con = mysql_connect($servidor, $usuario, $password) or die("Error al conectarse al servidor");
$sql= mysql_query("SELECT * FROM repuestos WHERE 'id','descripcion' LIKE '%$buscar%' ORDER BY id", $con); 
mysql_select_db($con, $base) or die("Error al conectarse a la base de datos"); !!(LINE 30)!!

$result = mysql_query($sql, $con);

// Tomamos el total de los resultados
$total = mysql_num_rows($result);
if($total>1){ 


      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["descripcion"]."</td> \n"; 

            echo "<td>".$row["cantidad"]."</td> \n"; 

            echo "</tr> \n"; 

      } while ($row = mysql_fetch_array($result));

            echo "</table> \n"; 
} else { 
echo "¡ No se ha encontrado ningún registro !"; 
} 
}
}
?> 

i'm using first for testing this a localhost server and DB

this is the error--->

Warning: mysql_select_db() expects parameter 1 to be string, resource given in C:\xampp\htdocs\maquinas2000\paginas\buscarepuestos.php on line 30
Error al conectarse a la base de datos
secretformula
  • 6,414
  • 3
  • 33
  • 56
  • 1
    replace `mysql_select_db($con, $base)` with `mysql_select_db($base, $con)` - dbname is first param – Phantom Jun 26 '14 at 14:44
  • Please be aware that the mysql_* functions are deprecated and should not be used in new code anymore. You should get yourself familiar with either mysqli or PDO. Read on [here](http://stackoverflow.com/a/14110189/2912456) – Rangad Jun 26 '14 at 15:26

1 Answers1

0

First parameter is the DB name and the second one is the resource

Change the parameters and it should work mysql_select_db($base, $con);

Katch
  • 170
  • 1
  • 20
  • Good! now i have the next error ._. Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\maquinas2000\paginas\buscarepuestos.php on line 35 ¡ No se ha encontrado ningún registro ! this is the line... $total = mysql_num_rows($result); (Line 35) – Ramón León Jun 26 '14 at 14:55
  • Your database query failed. Searching for that error should give you enough results. – Rangad Jun 26 '14 at 15:04
  • Your query is probably invalid or is empty. `if($result) { $total = mysql_num_rows($result); } else { die('Invalid query' . mysql_error()); } – Katch Jun 26 '14 at 15:04
  • i put that code Airoude, that says invalid query but no Line error, i'm looking the query and DB but i dont get the error ._. and thx guys.. – Ramón León Jun 26 '14 at 15:19
  • Last try: `mysql_query(...) or die(mysql_error());` – Katch Jun 26 '14 at 17:55