Script only number

0

I have a script that only allows typing numbers into input however when I type a phone number and saved in the database. The number is saved all scrambled. Example:

I type in input 27998439197 and in the database it saves as 2147483647.

Code:

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;   
    if((tecla>47 && tecla<58))
      return true;
    else{
    	if (tecla==8 || tecla==0) 
        return true;
	    else 
        return false;
    }
}
<input type="text" name="numero" class="form-control"
     id="exampleInputEmail1" maxlength="11"
     onkeypress='return SomenteNumero(event)' required />

PHP that inserts into the database:

<?php
session_start();

//apartir daqui faz o cadastro do usuario ao clicar no botão cadastrar que receber o nome de btnCadastrar
$btnCadastrar = filter_input(INPUT_POST, 'salvar', FILTER_SANITIZE_STRING);
if($btnCadastrar){
include_once ("../conn/conexao.php");
$dados = filter_input_array(INPUT_POST, FILTER_DEFAULT);
//aqui insere os dados na tb_usuario
$result_usuario = "INSERT INTO tb_numeros(numero, funcionario, rca, regiao, nchip, imei)VALUES(
	'".$dados['numero']."',
	'".$dados['funcionario']."',
	'".$dados['rca']."',
	'".$dados['regiao']."',
	'".$dados['nchip']."',
	'".$dados['imei']."'
	)";
	$mensagem="<script>
			alert('Numero ja cadastrado.');
			window.location='index.php';
		</script>";
$resultado_usuario = mysqli_query($conexao, $result_usuario) or die ($mensagem);
if($resultado_usuario):
	echo "<script>
			alert('Cadastrado Com Sucesso.');
			window.location='index.php';
		</script>"; 
else:
	echo "<script>
			alert('Ocorreu um erro ao cadastrar, entre em contato com o administrador.');
			window.location='index.php';
		</script>";
endif;
}

?>
    
asked by anonymous 27.11.2017 / 13:50

1 answer

5

You have reached the maximum value supported by type int in the database, try switching to a bigint type (if you really want to keep this as a value, I'd put a varchar )

See the limits of numeric data types in the image:

    
27.11.2017 / 14:03