variable pass to a select

Asked

Viewed 41 times

-3

I would like to pass the variable value $var into select, but gives the following error :

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\APOLLO\empresas.php on line 7  

Follow the code below:

$var = $_POST['empresa'];

include 'php/db_connect.php';
$result_usuarios = "SELECT $var FROM usuarios ";
    $resultado_usuarios = mysqli_query($connect, $result_usuarios);

    while($row_usuario = mysqli_fetch_assoc($resultado_usuarios)){

        echo "Categoria: " . $row_usuario['categoria'] . "<br>";

    }                                

1 answer

0

Good night, Missing quotes in your query! It looks like this:

"SELECT '". $var." ' FROM usuarios ";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.