I have a problem with a form that is used to insert data into a table, I need it to show a message if the data is inserted correctly or not. by the way, the actual code is not inserting anything to the table, but if I use directly the php file used to insert it, it works. this is the file with the form and the script: registrarrack.php
    <?php 
include('conexion.php');
session_start();
?>
<html>
<head>
    <title>Inicio</title>
    <link rel="stylesheet" type="text/css" href="style/stylef.css">
    <link rel="stylesheet" type="text/css" href="style/style.css">
    <script src="js/jquery-1.12.4.js"></script>
    <script> function myFunction() {
    document.getElementsByClassName("topnav")[0].classList.toggle("responsive");
    }
    function justNumbers(e)
        {
        var keynum = window.event ? window.event.keyCode : e.which;
        if ((keynum == 8))
        return true;
        return /\d/.test(String.fromCharCode(keynum));
        }
  function showContent() {
        element = document.getElementById("content");
        check = document.getElementById("check");
        if (check.checked) {
            element.style.display='block';
        }
        else {
            element.style.display='none';
        }
    }
    </script>
</head>
<!-- _________________________________________________________________AJAX Script___________________________________________________________________________--> 
<script>
    function Validar(Noserie, WO, Locacion, Modelo)
        {
            $.ajax({
                url: "registrarrackbackend.php",
                type: "POST",
                data: "Noserie="+Noserie+"&WO="+WO+"&Locacion="+Locacion+"&Modelo="+Modelo,
                success: function(resp){
                $('#resultado').html(resp)
                }       
            });
        }</script>
<!-- _________________________________________________________________End of AJAX Script___________________________________________________________________________--> 
<body class="desarroll">
    <header>
<div class="grupo">
            <div class="caja">
                <center><nav>
                    <ul class="topnav">
                        <li><a href="index.php">| Inicio |</a></li>
                        <li><a href="estatus.php">| Estatus |</a></li>
                        <li><a href="buscarnodo.php">| Buscar nodo |</a></li>
                        <li><a href="buscarrack.php">| Buscar rack |</a></li>
                        <li><a href="estadisticas.php">| Estadisticas |</a></li>
                        <?php  if(isset($_SESSION['Nombrers'])){ echo '<li><a href="logout.php">| Cerrar Sesion |</a></li>';}else{echo '<li><a href="#modal">| Iniciar Sesion |</a></li>';}?>
                    <li class="icon">
                        <a href="javascript:void(0);" onclick="myFunction()">☰</a></li>
                    </ul>
                </nav></center>
            </div>
        </div>
        <?php if(isset($_SESSION['Nombrers'])){ 
            echo '<center><div class="nombre" align="center">| '.$_SESSION['Nombrers'].' | '.$_SESSION['Mesamensrs'].' </div></center>';
        }?>
    </header>
<section>
            <!-- ********************LOGIN***********************************-->
            <?php  
            $query = mysqli_query($enlace, "SELECT Numero FROM mesas WHERE EnUso = '0'"); 
            if(!isset($_SESSION['Nombrers'])){  
                echo '<center> <div id="modal">
                <div class="modal-content ">
                    <div class="header">
                        <h2>Iniciar sesión</h2>
                        <center><hr width="150" align="center"/></center>
                    </div>
                    <div class="copy">
                        <div class="grupo">
                            <div class="caja">
                                <form method="post" action="login.php"  class="login">
                                <label style="color:#1BBC9B; font-weight:bold;">
                                    <input type="checkbox" style="width:0px; display:relative;" name="check" id="check" value="1" onchange="javascript:showContent()" >¿Técnico de reparación?</label><br>
                                    <div id="content" style="display: none;">
                                   <b>Mesas disponibles  :
                                   <input type="radio" name="mesa" style="width:0px; " value="0" checked="checked"> ';
            while ($datos=mysqli_fetch_row($query) ) {
        echo '<label><input type="radio" name="mesa" value="'.$datos[0].'" style="color:black; width:30px;">'.$datos[0].'</label>    ';
    }
            echo '</b>
                                    </div>
                                    <input type="text" name="NoReloj" placeholder="Número de reloj" required maxlength="5" onkeypress="return justNumbers(event);">
                                    <input type="password" name="Pass"  placeholder="Contraseña" required>
                                    <input type="hidden" name="Url" value="index.php#">
                                    </script>
                                    <button class="btn1">Aceptar</button>
                                    <input class="btn2" type="button" value="Cerrar" onClick="window.location.href=\'#\'">
                                </form>
                            </div>
                             </div>
                        </div>
                    </div>
                    <div class="overlay"></div>
                </div></center>'
                ;
}
                echo '<center> <div id="modalmesa">
                <div class="modal-content ">
                    <div class="header">
                        <h2>Elegir mesa</h2>
                        <center><hr width="150" align="center"/></center>
                    </div>
                    <div class="copy">
                        <div class="grupo">
                            <div class="caja">
                                <form method="post" action="elegirmesa.php"  class="login">
                                <div id="resultado"></div>
                                    <input type="hidden" name="Url" value="index.php#">
                                    </script>
                                    <button class="btn1">Aceptar</button>
                                </form>
                            </div>
                             </div>
                        </div>
                    </div>
                    <div class="overlay"></div>
                </div></center>'
                ;
            ?>
<!-- _________________________________________________________________Form___________________________________________________________________________-->            
            </section>
            <center>
<?php  $query = mysqli_query($enlace, "SELECT Nombre FROM familia"); ?>
<div class="grupo-centar">
<div class="caja">
<br><br>
<h2>Registrar rack</h2><br>
<div id="resultado"></div>
<table class="tablaregistro">
<tr>
    <form class="RegistroR" method="POST" action="return false" onsubmit="return false" id="formregistro">
    <td><input type="text" name="Noserie" id="Noserie" placeholder="Número de serie" required form="formregistro" maxlength="10" pattern=".{10,}"  ></td>
</tr>
<tr>    
    <td><input type="text" name="WO" id="WO" placeholder="WO" required form="formregistro" maxlength="9" pattern=".{9,}"></td>
</tr>
<tr>    
    <td><input type="text" name="Locacion" id="Locacion" placeholder="Locación: TRXX-XX" required form="formregistro" maxlength="8" pattern=".{7,}"></td>
</tr>
<tr>
<td><Select name="Modelo"  id="Modelo" required form="formregistro" placeholder="Modelo">
    <option  value="" disabled selected>Modelo</option>
<?php  
while ($datos=mysqli_fetch_row($query) ) {
        echo '<option  value="'.$datos[0].'">'.$datos[0].'</option>';
    }
?>
</Select></td>
</tr>
<tr>
<td><Button class="btnregistrar" form="formregistro" onclick="Validar(document.getElementById('Noserie').value, document.getElementById('WO').value, document.getElementById('Locacion').value, document.getElementById('Modelo').value);"><h1>Registrar</h1></Button></td>
</tr>
</table>
    </form>
</center>
</div>
</div>
             <section>
<!-- _________________________________________________________________AJAX Script___________________________________________________________________________-->                 
</body>
</html>
and heres the other php file: registrarrackbackend.php
<?php 
error_reporting(0);
include('conexion.php');
session_start();
$NoSerie = $_POST['Noserie'];
$Locacion = $_POST['Locacion'];
$WO = $_POST['WO'];
$Familia = $_POST['Modelo'];
$Tecnico = $_SESSION['No_Relojrs'];
$consulta=mysqli_query($enlace, "SELECT * FROM rack WHERE NoSerie= '$NoSerie'");
if($cons=mysqli_fetch_array($consulta)){
    echo '<span>Error: rack is already registered</span>';
}else{
    $sql2="INSERT INTO rack (NoSerie, WO, Familia, Locacion, Tecnico) VALUES ('$NoSerie','$WO' ,'$Familia','$Locacion','$Tecnico')";
     if(mysqli_query($enlace, $sql2)){
        //echo "<script>location.href = 'index.php'</script>";
        echo '<span>rack was successfully registered</span>';
    }else{echo "<span>Error updating record: " . mysqli_error($conn).'</span>';}
}
 ?>
I don't know what is wrong with the code, I hope you can help me please. and sorry for my bad english
