Paul. You probably have a problem with your consultation.
Assuming the user typed "Church" in the form and made a Ubmit you will have the following code within the page itself (or another) to receive the data and perform the query by type;
if (isseet($_POST['tipoConteudo']) && $_POST['tipoConteudo'] != "") {
$nomeConteudo = $_POST['tipoConteudo'];
echo $nomeConteudo;
}
If it was made a $_POST
and this value is different from empty you will perform the query. Then let the function:
function requestID($nomeConteudo){
$query = "SELECT id FROM conteudo WHERE nomeConteudo LIKE '%$nomeConteudo%'";
$id = mysqli_query($this->connection, $query);
return $id;
}
If you are not sure that the word the user typed in the form is the same as the database I recommend using the operator LIKE
SQL. Otherwise you can use a simple =
, but you’ll have to make sure the words are the same.
Going back to the form page script let’s call the method. For this, I will use a class called Content, where the method is requestID
.
if (isseet($_POST['tipoConteudo']) && $_POST['tipoConteudo'] != "") {
$nomeConteudo = $_POST['tipoConteudo'];
echo $nomeConteudo;
$Conteudo = new Conteudo();
$id_consulta = $Conteudo->requestID($nomeConteudo);
echo $id_consulta;
}
Having the query method ready the rest was simple. It was enough to instantiate the class where the method was and pass the variable received by $_POST
as a parameter.
Tip:
Do not work with Strings to perform query (unless necessary). The ideal, if possible, would be to work with the ID, which would bring more performance to the query and a greater guarantee of "success" in it.
See more:
LIKE operator
Practical guide to mysqli in PHP
Duplicate: https://answall.com/q/326721/99718
– Valdeir Psr