Paul. You're probably having trouble with your query.
Assuming that the user typed "Church" in the form and made a submit you will have the following code inside 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 a $_POST
has been made and this value is different from empty you will perform the query. So let's 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 that the user typed in the form is the same as the database I recommend using the LIKE
SQL operator. Otherwise you can use a simple =
, but you have to make sure the words are the same.
Returning to the page script of the form we will call the method. For this, I'm going to use a class called Content, where the requestID
method is found.
if (isseet($_POST['tipoConteudo']) && $_POST['tipoConteudo'] != "") {
$nomeConteudo = $_POST['tipoConteudo'];
echo $nomeConteudo;
$Conteudo = new Conteudo();
$id_consulta = $Conteudo->requestID($nomeConteudo);
echo $id_consulta;
}
Having the consultation 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 query (unless necessary). Ideally, if you can, it would work with the ID, which would bring more performance to the query and a greater guarantee of "success" in it.
See more:
Operator LIKE
Practical guide to mysqli in PHP