You have an error in your SQL syntax????

Enviada por Antonio Junior 
Antonio Junior
You have an error in your SQL syntax????
10 de December de 2019 às 05:38PM
Tenho o codigo abaixo e existe dois problemas:
1 - Tá exibindo esse erro: Fatal error: "Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20,20' at line 1 in" ( que são essas duas variaveis '.$inicio.','.$maximo;)
2 - Nao tá considerando o "if (empty($termo)):" e não executa a consulta no banco.

alguem tem alguma dica?

<?php
include_once "conexao.php";

$pagina = filter_input(INPUT_POST, 'pagina');
$maximo = 20;
//calcular o inicio visualização
$inicio = ($pagina * $maximo) - $maximo;
// Recebe o termo de pesquisa se existir
$termo = (isset($_GET['termo'])) ? $_GET['termo'] : '';

// Verifica se o termo de pesquisa está vazio, se estiver executa uma consulta completa
if (empty($termo)):
$conexao = conexao::getInstance();
$sql = 'SELECT * FROM person ORDER BY nome ASC LIMIT '.$inicio.','.$maximo;
$stm = $conexao->prepare($sql);
$stm->execute();
$total = $stm->rowCount();
$clientes = $stm->fetchAll(PDO::FETCH_OBJ);

else:
// Executa uma consulta baseada no termo de pesquisa passado como parâmetro
$conexao = conexao::getInstance();
$sql = 'SELECT * FROM person WHERE nome LIKE :nome OR categoria LIKE :categoria ORDER BY nome ASC LIMIT '.$inicio.','.$maximo;
$stm = $conexao->prepare($sql);
$stm->bindValue(':nome', $termo.'%');
$stm->bindValue(':categoria', $termo.'%');
$stm->execute();
$total = $stm->rowCount();
$clientes = $stm->fetchAll(PDO::FETCH_OBJ);
endif;
?>
AQUI VISUALIZA OS DADOS DA TABELA

<?php if(!empty($clientes)):?>
<div class="container">
<div class="component">
Clientes registrados: <?=$total?>
<table>
<thead>
<tr>
<th>Foto</th>
<th>Nome</th>
<th>Altura(m)</th>
<th>Categoria</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php foreach($clientes as $cliente):?>
<tr>
<td class="user-name">
<img src='fotos/<?=$cliente->foto?>' height='40' width='40'>
</td>
<td><?=$cliente->nome?></td>
<td><?=$cliente->altura?></td>
<td><?=$cliente->categoria?></td>
</tr>
</tbody>
<?php endforeach;?>
</table>
</div>
</div>
Você precisa estar logado no PHPBrasil.com para poder enviar mensagens para os nossos fóruns.

Faça o login aqui.