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

10/12/2019

0

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> </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>
Junior Mota

Junior Mota

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar