condition to show data in combobox

Asked

Viewed 46 times

1

Galera is the following I have two forms, one of development registration and another of process registration, and in the process has a ComboBox where it is pulled all the projects that were registered, remembering that the process form is called as soon as it is finalized the registration of enterprise.

The system user can open both forms depending on their need, however, if the user opened the enterprise form and made a registration as soon as it was called the process form would like the ComboBox shows only the last registered enterprises, but if the user only wants to see the registered enterprises in the process form were displayed all the projects in the ComboBox.

Personal Speech follows only from the most important parts of the code:

Property registration form

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {        
    }
} else {
    header("Location:login.php");
    exit();
}
?>

<form  action="recebe_cad_empreendimento.php"  method="POST" name="frmempreendimento" id="frmempreendimento">
    <div class="panel panel-success">
        <div class="panel-heading"> 
            <div class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapse1"><strong>DADOS DO EMPREENDIMENTO / ATIVIDADE</strong></a>
            </div>
        </div>
        <div id="collapse1" class="panel-collapse collapse in">
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label for="empreendimento"><strong>NOME DO EMPREENDIMENTO*</strong></label>                                  
                            <input type="text" name="empreendimento" id="empreendimento" class="form-control">   
                        </div>                                  
                    </div>
                </div>                           
            </div>
        </div>                                             
    </div>                                                          
    <div class="panel panel-default">
        <div class="panel-title" style="text-align: center;"><br/>
            <input type="submit" value="REALIZAR CADASTRO" class="btn btn-success" style="font-size: 17px; font-weight: bold;"/>
            <button  class="btn btn-danger"><a href="home.php"  style="font-size: 17px; font-weight: bold; color: #fff;text-decoration: none;">CANCELAR CADASTRO</a></button><br/><br/>
        </div>   
    </div> 
</form>

Page that receives the data of the development form (Recebe_cad_empreendiemeto.php)

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {

    }
} else {
    header("Location:login.php");
    exit();
}
if (isset($_POST['nome_empreendimento']) && empty($_POST['nome_empreendimento']) == FALSE) {

    $nome_empreendimento = strtoupper(addslashes($_POST['nome_empreendimento']));

    $sql = "INSERT INTO tb_empreendimento(nome_empreendimento)"
            . "VALUES(UPPER('$nome_empreendimento')";
    mysqli_query($con, $sql);
    ?>               
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">EMPREENDIMENTO CADASTRADO COM SUCESSO!</h4>
                </div>
                <div class="modal-footer">
                    <a href="cad_licenca.php"><button type="button" class="btn btn-danger">CONTINUAR CADASTRO</button></a>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $('#myModal').modal('show');
        });
    </script>
    <?php
}

Process registration form

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {

    }
} else {
    header("Location:login.php");
    exit();
}
?>
<form  action="recebe_cad_processo.php"  method="POST" name="frmprocesso" id="frmprocesso">
    <div class="panel panel-success">
        <div class="panel-heading"> 
            <div class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapse1"><strong>DADOS DO PROCESSO</strong></a>
            </div>
        </div>
        <div id="collapse1" class="panel-collapse collapse in">
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">                                                
                            <label for="empreendimento"><strong>SELECIONE O EMPREENDIMENTO*</strong></label><a href="cad_empreendimento.php" style="float: right;font-size: 16px"><strong>caso não encontre,faça o cadastro - aqui</strong></a><br/>
                            <select name="empreendimento" id="empreendimento" class="form-control" autofocus="">
                                <option value="">--- SELECIONE ---</option>
                                <?php
                                $parametro_empreendimento = filter_input(INPUT_GET, "parametro_empreendimento");
                                $empreendimento = "SELECT *FROM tb_empreendimento WHERE nome_empreendimento LIKE '%$parametro_empreendimento' ORDER BY nome_empreendimento";
                                $recebe_empreendimento = mysqli_query($con, $empreendimento);
                                while ($linha = mysqli_fetch_array($recebe_empreendimento)) {
                                    echo '<option value="' . $linha['codigo_empreendimento'] . '">' . $linha['nome_empreendimento'] . '</option>';
                                }
                                ?>                                                                       
                            </select>
                        </div>
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label for="numero_processo"><strong>NÚMERO DO PROCESSO *</strong></label><br/>
                                <input type="number" name="numero_processo" id="numero_processo" class="form-control" autofocus=""/>
                            </div>
                        </div>
                    </div>
                </div>                                     
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-title" style="text-align: center;"><br/>
            <input type="submit" value="REALIZAR CADASTRO" class="btn btn-success" style="font-size: 17px; font-weight: bold;"/>
            <button  class="btn btn-danger"><a href="home.php"  style="font-size: 17px; font-weight: bold; color: #fff;text-decoration: none;">CANCELAR CADASTRO</a></button><br/><br/>
        </div>   
    </div>
</form>

Page that receives the data from the process form (Recebe_cad_processo.php)

<?php
session_start();
require './config/conexao.php';

if (isset($_SESSION['email']) && empty($_SESSION['email']) == FALSE) {
    if (isset($_SESSION['senha']) && empty($_SESSION['senha']) == FALSE) {

    }
} else {
    header("Location:login.php");
    exit();
}

if (isset($_POST['empreendimento']) && empty($_POST['empreendimento']) == FALSE) {
    if (isset($_POST['numero_processo']) && empty($_POST['numero_processo']) == FALSE) {

        $empreendimento = strtoupper(addslashes($_POST['empreendimento']));
        $numero_processo = strtoupper(addslashes($_POST['numero_processo']));

        if ($numero_processo < 0) {
            ?>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">ERRO! O NÚMERO DO PROCESSO INFORMADO É INVÁLIDO</h4>                           
                        </div>
                        <div class="modal-footer">
                            <a href="cad_licenca.php"><button type="button" class="btn btn-info">POR FAVOR! INFORME OUTRO NÚMERO</button></a>
                            <a href="home.php"><button type="button" class="btn btn-danger">CANCELAR</button></a>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                $(document).ready(function () {
                    $('#myModal').modal('show');
                });
            </script>
            <?php
        }

//verrificando se ja existe no banco de dados o numero do processo informado
        $consulta_processo = "SELECT *FROM tb_processo WHERE numero_processo ='" . $_POST['numero_processo'] . "' ";
        $recebe_consulta = mysqli_query($con, $consulta_processo);

        if (mysqli_num_rows($recebe_consulta) > 0) {
            ?>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">ERRO! JÁ EXISTE UM PROCESSO COM O NÚMERO INFORMADO</h4>                           
                        </div>
                        <div class="modal-footer">
                            <a href="cad_licenca.php"><button type="button" class="btn btn-info">POR FAVOR! INFORME OUTRO NÚMERO</button></a>
                            <a href="home.php"><button type="button" class="btn btn-danger">CANCELAR</button></a>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                $(document).ready(function () {
                    $('#myModal').modal('show');
                });
            </script>

            <?php
        } else {

            $sql = "INSERT INTO tb_processo(fk4_codigo_empreendimento,numero_processo)"
                    . "VALUES('$empreendimento','$numero_processo')";
            mysqli_query($con, $sql);
            ?>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">PROCESSO CADASTRADO COM SUCESSO!</h4>
                        </div>
                        <div class="modal-footer">
                            <a href="cad_licenca.php"><button type="button" class="btn btn-danger">CONTINUAR CADASTRO</button></a>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                $(document).ready(function () {
                    $('#myModal').modal('show');
                });
            </script>
            <?php
        }
    }
}
?>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">ERRO! POR FAVOR PREENCHA O FORMULÁRIO</h4>
            </div>
            <div class="modal-footer">
                <a href="cad_processo.php"><button type="button" class="btn btn-info"><strong>VOLTAR PARA O FORMULÁRIO DE CADASTRO</strong></button></a>
                <a href="home.php"><button type="button" class="btn btn-danger"><strong>CANCELAR</strong></button></a>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $('#myModal').modal('show');
    });
</script>

  • and where’s your code so we can help? xD

  • Before asking a question a look at this here https://answall.com/help/how-to-ask. Show application code.

No answers

Browser other questions tagged

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