-1
I have tried several ways, but all of the problem in the query...
Exemplo :
<form class="form-inline my-2 my-lg-0" method="post" action="home.php">
<input class="form-control mr-sm-2" type="text" name="palavra"
placeholder="Pesquisar" aria-label="Search"> <button class="btn btn-
outline-
danger my-2 my-sm-0" type="submit">Pesquisar</button>
</form>
<?php
if(isset($_POST['palavra']) != '')
{
$palavra = $_POST['palavra'];
$pesquisa = "where nome like '%palavra%' ";
}
else
{
$pesquisa = '';
}
$querySelect = $link->query("select * from alunos $pesquisa");
$linhas = mysqli_num_rows($querySelect);
echo "Foram encontrados $linhas registros";
echo '<br>';
?>
Function
isset
returns a boolean, so it makes no sense to makeisset($_POST['palavra']) != ''
. See the documentation. Other than that, I recommend describing which "query errors" you got.– Woss
Ah... I am beginner in this, I saw in a tutorial that it worked for everyone... but not for me... the errors are : Notice: Undefined variable: link in C: xampp htdocs Horus home.php on line 34 'Fatal error: Uncaught Error: Call to a Member Function query() on null in C: xampp htdocs Horus home.php:34 Stack trace: #0 {main} thrown in C: xampp htdocs Horus home.php on line 34'
– Verônica Emschermann
The variable
$link
, which connects to the bank, does not exist. Where?– Woss
define it in the connection.php : <?php $utf8 = header ("Content-Type: text/html; charset=utf-8"); $link = new mysqli('localhost', 'root', 'Horus'); $link->set_charset('utf8'); ; ?>
– Verônica Emschermann
This file is not listed as included in your example. Could you describe your problem better? Sometimes omitting some parts of the code makes it impossible to answer the question.
– Woss
Ah...I hadn’t really included the.php connection link on my home.php page (where you’re doing the search filter), now that it includes... it doesn’t show me any more errors, but it doesn’t do the search...
– Verônica Emschermann
'%palavra%'
should be'%{$palavra}%'
– Woss
Anderson, thanks for trying to help me by putting '%{$word}%' gave error : Notice: Undefined variable: word in C: xampp htdocs Horus home.php on line 36
– Verônica Emschermann
Impossible, you set the variable in the previous line. You changed something else in the code?
– Woss
no! kkkk I haven’t changed at all...
– Verônica Emschermann
Anderson, I mosqued, I’m sorry. Well it seems that we are on the right track, I made the change to '%{$palavra}%' now and when I search the name "Daniela" really returns me 1 record, but only shows the text : "1 records have been found" but it’s not just the Daniela record... it’s still showing all 120 students...
– Verônica Emschermann
This is another problem, which was not addressed in this question. I recommend you open another by placing the code related to the listing.
– Woss
thanks! at the moment I can not ask the question the site says "reached the limit of questions" kkkk....
– Verônica Emschermann