Search records in a database using PHP and MySql

0

For a school project I was asked to make a page where I can search for specific records in a database inside a hosting, it turns out that when trying to make the query I always throw this error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in 
/home/u538782983/public_html/php/resultado.php on line 9.

This is my code:

<?php
include 'cn.php';

$codigo = $_POST['codigo'];
mysqli_select_db($link, $bd) or die ("Error al conectar a la base de Datos");
$result = mysqli_query($link, "SELECT * FROM registro_cbtis253 WHERE Codigo = '$codigo");

while ($row = mysqli_fetch_array($result)) {
    echo $row['Codigo'].$row['nombre_escuela'];
}
?>
    
asked by Brayan Pineda 30.05.2017 в 14:29
source

2 answers

1

You have an erratum in the query, that's why you are not returning results

<?php
include 'cn.php';

$codigo = $_POST['codigo'];
mysqli_select_db($link, $bd) or die ("Error al conectar a la base de Datos");
$result = mysqli_query($link, "SELECT * FROM registro_cbtis253 WHERE Codigo = '$codigo' ");

while ($row = mysqli_fetch_array($result)) {
    echo $row['Codigo'].$row['nombre_escuela'];
}
?>

Missing a quote in $ code

    
answered by 30.05.2017 в 14:36
0

Try this, if in the query sql first is the Codigo and then    nombre_escuela $ row [0] would be code and $ row [1] the name

 <?php
            include 'cn.php';

            $codigo = $_POST['codigo'];
            mysqli_select_db($link, $bd) or die ("Error al conectar a la base de Datos");
            $result = mysqli_query($link, "SELECT * FROM registro_cbtis253 WHERE Codigo = '$codigo' ");

            while($row = mysqli_fetch_array($result)){
                $cod = $row[0];
                $nom= $row[1];
            }

        ?>
    
answered by 30.05.2017 в 15:23