简体   繁体   中英

desire to make a parts search on my website, but throws me errors in php, I still have no idea about the error

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM