Script only number

Asked

Viewed 146 times

0

I have a script that only lets you type numbers into one input however when I type a phone number and save it to the database. The number is saved all scrambled. Example:

Type in the input 27998439197 and in the bank he 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 seat:

<?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;
}

?>

  • The problem seems to be in php;

  • ready @rray edited

  • ready @Caiqueromero edited

  • Number is a scan in the database?

  • @rray number and int (11)

  • If it’s a phone it should be a varchar.

  • I just let him type number so I put int, you know? na will have characters

  • You once made one die($result_usuario); to see what is how its formed?

  • 1

    Ferb the int does not allow zero the left imagines that will save a 0800 of life, then your field will not suit you.

Show 4 more comments

1 answer

5


You have reached the maximum value supported by the type int at the bank, try trading for a guy bigint (If you really want to keep that kind of value, I would put a sweep)

See the limits of numerical date types in the image:

inserir a descrição da imagem aqui

Browser other questions tagged

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