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;
– rray
ready @rray edited
– Ferb
ready @Caiqueromero edited
– Ferb
Number is a scan in the database?
– rray
@rray number and int (11)
– Ferb
If it’s a phone it should be a varchar.
– rray
I just let him type number so I put int, you know? na will have characters
– Ferb
You once made one
die($result_usuario);
to see what is how its formed?– Caique Romero
Ferb the int does not allow zero the left imagines that will save a 0800 of life, then your field will not suit you.
– Caique Romero