PHP-MySQL-Dialog

1

I'm doing a page, where I have a mySQL database connecting to PHP.

What I wanted is the following, I have a form with: pais(combo); nome(text);empresa(text) , and I want it:

  • When you fail to complete any of the fields, please let me know I must fill in all fields ;

  • If the fields are filled it should validate if it is a duplicate record and show the name in question; Ex: " John has already been registered!"

  • But I wanted him to show me these alerts in Bootstrap Dialog. Is it possible to do this?

        
    asked by anonymous 03.09.2015 / 14:37

    1 answer

    0

    Just adapt to its use and follow a practical example.

    /// PHP Code

        $campEmail  = $_POST['campEmail'];
    
        // faz consulta no banco
        $sql = "SELECT * FROM usuarios WHERE email ='".$campEmail.";
        $consulta = mysql_query($sql);
        $count = mysql_num_rows($consulta);
    
    if(count > 0){
        while($linhas = mysql_fetch_array($consulta)) {
            echo $linhas["Nome"];
        }
    }
    else{
        echo "";
    }
    

    /// Jquery Code

    function buscarUsuario() {
            var email    = $("#cmpEmail").val();
    
            if (email != "" && email != undefined) {
                $.ajax({
                    url: "./buscar.php",
                    method: "POST",
                    data: {campEmail: email },
                    async: false,
                    cache: false,
                    success: function (data) {
                        if (data != "") {
                           $('#modalConfirm').modal('show');
                           $('#msgRetorno').text("O usuário " + data + " já foi cadastrado!");
                        }
                        else {
                           $('#modalConfirm').modal('show');
                           $('#msgRetorno').text("Não existe na base!");
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        throw "Ocorreu uma falha ao verificar a estabilidade do funcionário, tente novamente.";
                    }
                });
            }
            else {
                $('#modalConfirm').modal('show');
                $('#msgRetorno').text("Preencha todos os dados!");
            }
        }
    

    /// Modal Html Code

          <div class="modal fade" id="modalConfirm" role="dialog">
            <div class="modal-dialog">
    
              <!-- Modal content-->
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">Modal Header</h4>
                </div>
                <div class="modal-body">
                  <p id="msgRetorno"></p>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
              </div>
    
            </div>
          </div>
    
        
    03.09.2015 / 15:09