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?