PHP-Mysql-Dialog

Asked

Viewed 162 times

1

I’m making a page, where I have a mysql database connecting with PHP.

What I wanted is this, I have a form with: pais(combo); nome(text);empresa(text), and I want you to:

  1. When you fail to complete any of the fields, let me know must fill in all fields;

  2. If the fields are filled in it should validate whether it is a duplicate record and display the name in question; e.g.: "O John has already been registered!"

But I wanted him to show me these alerts in the Bootstrap Dialog. You can do this?

  • 1

    What have you tried?

  • 1

    You can do this using the Modal window, you already have PHP which checks for duplicate record and inserts?

  • Yes you can use jquery to validate the fields and ajax to check if there is the record, if yes in the return you will have the answer if yes or no and then just use the modal to display the message

  • Andre, yes I do the check if you already have registration with php. I just wanted to show in Dialog the result.

  • Rodrigo, Voce would have an example, or easy script to share. I’m new to php, I’m learning reading the forums rs. Thank you

  • For security reasons I think you should also validate on the server-side

Show 1 more comment

1 answer

0

Just adapt to your use more follows 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!");
        }
    }

///Html Modal 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>
  • This code has no SQL Injection risk no? o.o

  • Do you have this complete code Rodrigo? Here I rode but did not roll =/ ..

Browser other questions tagged

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