Ajax help does not send data to the bank

0

I'm trying to send a form to my database. Ajax says that the user registration has been successfully done but when I go to look at the database there is nothing there.

My Form.

<form class="form3" method="POST" enctype="multipart/form-data">
    <div id="ressult"></div>

    <p>Nome completo</p>
    <input type="text" name="Nome_us" placeholder="Nome completo *">

    <p>Nome de usuário</p>
    <input type="text" name="Nick_us" placeholder="Nick da conta *">

    <p>E-mail</p>
    <input type="text" name="Email_us" placeholder="Informe seu E-mail *">

    <p>Senha</p>
    <input type="password" name="Senha_us" placeholder="Informe a sua senha *">

    <input type="hidden" name="Imagem_us" value="/images-profile/Profile_img_00_TSN.png">
    <input type="submit" id="Bot_Cria_login" name="Cadastrar_us" value="Criar conta">
</form>

My ajax.

<script>
    $(function(){
        $('.form3').submit(function(event){
            event.preventDefault();
            var formDados = $('.form3');

            $.ajax({
                location:'/arquivos/conta_usuario.php',
                type:'POST',
                data:formDados,
                cache:false,
                contentType:false,
                processData:false,
                success:function(data){
                    $('#ressult').html(data);
                    alert('Cadastrado com sucesso!');
                },
                dataType:'html'
            });
            return false;
        });
    });
</script>

My php where I want to send the data I filled out.

<?php
    require_once('conex.php');

    if(isset($_POST['Cadastrar_us'])){
        $Nome_user      = $_POST['Nome_us'];
        $Nick_user      = $_POST['Nick_us'];
        $Email_user = $_POST['Email_us'];
        $Senha_user = $_POST['Senha1_us'];
        $Imagem_user    = $_POST['Imagem_us'];

        if($Nome_user == ""){
            echo 'Preencha o campo Nome corretamente.';
        }
        else{
            $SQL_Cadastro = mysqli_query($conex,"INSERT INTO Usuarios_login_s_n (Nome_us_sn, Nick_us_sn, Email_us_sn, Senha_us_sn, Foto_us_sn) VALUES ('$Nome_user', '$Nick_user', '$Email_user', '$Senha_user', '$Imagem_user')");
        }
    }
    else{

    }
?>
    
asked by anonymous 27.02.2018 / 02:44

1 answer

1

In the line below, you are sent the HTML form, not the data:

var formDados = $('.form3');

To store the form data to the variable, use the .serialize() method:

var formDados = $('.form3').serialize();

% w / w% is also wrong. Remove it that will be sent as standard. Also change% Ajax% by contentType .

The fact that you're picking up on the alert does not mean that the data has been received, it just means something is returning without making any mistakes.

Your Ajax looks like this:

$(function(){
  $('.form3').submit(function(event){
      event.preventDefault();
      var formDados = $('.form3').serialize();

      $.ajax({
          url:'/arquivos/conta_usuario.php',
          type:'POST',
          data:formDados,
          cache:false,
          processData:false,
          success:function(data){
              alert('Cadastrado com sucesso!');
          },
          dataType:'html'
      });
      return false;
  });
});
    
27.02.2018 / 02:50