MYSQLI error with _GET attribute - Fatal error: Call to a member function error () on a non-object in

1

I have a problem and I do not know how to solve it.

I'm using MYSQLI to query a database using GET to get the name of the table where the query should be done.

BD connection code:

$hostbd = "localhost";
$usuariobd = "usuario";
$senhabd = "senha";
$bancobd = "bd";

// Conecta ao banco de dados
$mysqli = new mysqli($hostbd, $usuariobd, $senhabd, $bancobd);
// Verifica se ocorreu algum erro
if (mysqli_connect_errno()) {
    die('Não foi possível conectar-se ao banco de dados: ' . mysqli_connect_error());
    exit();
}

The code is:

$sql = $mysqli->prepare('SELECT * FROM ? ORDER BY 'id' DESC');
$modulo = $_GET["modulo"];
$sql->bind_param('s', $modulo);
$sql->execute();
$RESULT = get_result($sql);
$sql->store_result();
$registro = $sql->num_rows;

if ($registro < 1) {
    echo "resultado";
}

When accessing the page the following error is displayed:

  

Fatal error: Call to a member function bind_param () on a non-object in   /path/modulo.php on line 24

Line 22 is this: $ sql-> bind_param ('s', $ module);

I have already printed the variable $modulo and it is pulling the right name of the table, if I put the table name in the variable $ module the problem still persists which shows me that the problem is not the GET . If I put the name of the direct table in the query the error is not displayed and it works normally.

Does anyone have any idea what it might be?

    
asked by anonymous 13.02.2017 / 10:53

1 answer

1

You're wrong with your SQL syntax; you can not use the bind_param method to bind the table name, so the prepare method must be returning false and not the statement object, so try adding the table name directly in the SQL that should work .

    
13.02.2017 / 11:17