Help with the following code, I do not know what the error could be [duplicated]

2

Form:

    <!DOCTYPE html>
    <html lang="en">
        <head>
        	<meta charset="UTF-8">
        	<link rel="stylesheet" type="text/css" href="css/style.css">
        	<title>Validacion de clientes</title>
        </head>
        <body> 
        	tr>
        		<h1>Validacion de Clientes</h1>
        		<td><label>Codigo del Cliente</label></td>
        		<!--<td><input type="text" name="codigo_cliente" placeholder="Codigo" required/></td>-->

        		<form action="buscar.php" method="post">
        			<td><input type="text" name="codigo" placeholder="ingrese Codigo" required/></td>
        			<!--<input=type="text" name="codigo" placeholder="Ingrese codigo">-->
        		   <td><label><input type="submit" name="name" value="Buscar">	
        		</form>

        	</div>
        </body>
    </html>

Connection:

 <?php   
     $server = "127.0.0.1";
     $user = "root";
     $pass ="";
     $db = "client_cxp"; 
     $conexion=new mysqli($server,$user,$pass);
     //$conexion = mysql_connect($server,$user,$pass) or die ("Error al conectarse");
     //$conexion = mysql_connetc($server,$user,$pass) or die("Error"); 
   ?>

Search:

<?php
     include ("conexion.php");
     $codigo = $_POST['codigo'];
     mysqli_select_db ($conexion,$db) or die ("Error de conexion");
     $registros = mysqli_query("SELECT * FROM client_cartera WHERE codigo_cliente = '$codigo'") or die ("Error de consulta");

     while ($registro = mysqli_fetch_array($registros))
       {  
          echo $registro['codigo_cliente']." ".$registro['Nom_cliente']." ".$registro['Cartera_vencida']." ".$registro['Cartera_actual']." ".$registro['Cartera_total']." ".$registro['Plazo_credito']." ".$registro['Limit_credito'];
        }  
   ?>

This error is generated:

 Warning: mysqli_query() expects at least 2 parameters, 1 given in

C:\xampp\htdocs\Consulta\buscar.php on line 5 Error de consulta
    
asked by Zephyrot GM 12.12.2018 в 23:04
source

1 answer

-3

The problem is that, in procedural programming, mysqli_query needs two parameters: the resource of the connection, and the query itself. Anyway, if you can refactor your code, I suggest you go to PDO. See link and in link

Regarding the undefined index, you have not published the structure of your tables, but I think that's where you should look.

    
answered by 22.12.2018 в 21:24