Fill in SELECT via form (PHP)

Asked

Viewed 416 times

0

I have the following code:

<?php
include("conexao.php");

$sql = mysql_query("SELECT COUNT(*) 
FROM escola e
WHERE coordenador IN (SELECT ec.coordenador 
               FROM escola_coordenador ec 
              WHERE ec.coordenador = '1')
AND uf = 'PR' AND situacao = 'contratado'");
$row = mysql_fetch_array($sql); 
$total = $row['COUNT(*)'];
echo $total;

?>

It shows the amount of registration in the bank.

I need a form for the user to enter: the coordinator’s number and the UF and then appears the amount in $total.

Someone can help me?

  • What you know about HTML and HTTP?

  • @Andersoncarloswoss, almost nothing :-/

  • 1

    So I think it’s best to start studying from the beginning and try to do it by yourself first, to better identify your difficulties.

1 answer

0


I managed to solve my problem.

I created an index.html file:

<form action="script.php" method="post">
Coordenador <input type=text name=coordenador><br>
Estado (UF): <input type=text name=uf><br>
<input type=submit value="Buscar">
</form>

And a script.php file:

<?php
include("conexao.php");

$coordenador = $_POST["coordenador"];
$uf = $_POST["uf"]

$sql = mysql_query("SELECT COUNT(*) 
FROM escola e
WHERE coordenador IN (SELECT ec.coordenador 
               FROM escola_coordenador ec 
              WHERE ec.coordenador = '$coordenador')
AND uf = '$uf' AND situacao = 'contratado'");
$row = mysql_fetch_array($sql); 
$total = $row['COUNT(*)'];
echo $total;

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.