-5
File 1 picks up the data to enter into the database, the name and email are correctly being recorded, but the phone does not go to the database.
FILE 1
<script type="text/javascript">
function validar()
{
var nome = formulario.nome.value;
// valida nome
if (nome == "")
{
alert('Preencha o nome da pessoa!');
formulario.nome.focus();
return false;
}
return true;
}
</script>
<form action="pessoas_incluir.php" method="POST" name="formulario" >
<label>Nome da Pessoa </label>
<input type="text" name="nome" value="" size="40" maxlength="40" required onblur="javascript:this.value=this.value.toUpperCase();" autofocus>
<br><br>
<label>Email</label>
<input type="text" name="email" value="" size="40" maxlength="40" required>
<br><br>
<label>Telefone</label>
<input type="text" name="fone" value="" size="15" maxlength="14" required>
<br><br>
<button type="submit" onClick="return validar()">Salvar</button>
<button type="reset">Limpar</button>
</form>
PERSONAL files_include.php
<?php
include_once "../conexao.php";
$conn = mysqli_connect($localhost, $user, $password, $banco);
if (!$conn)
{
echo "<script>alert('Não foi possível conectar ao Banco de Dados!');</script>";
}
else
{
// recebe parametro
$nome = $_POST['nome'];
$email = $_POST['email'];
$fone = $POST['fone'];
// monta QUERY
$sql = "INSERT INTO PESSOAS (Nome, Email, Telefone) VALUES ('$nome','$email','$fone')";
$result = mysqli_query($conn, $sql);
if (! $result)
{
echo "Erro na inclusão dos dados!";
}
else
{
echo "Dados incluídos com sucesso!";
}
}
mysqli_close($conn);
header("Location: pessoas_mostra.php");
?>
Lucas we need more details to be able to offer you an answer.
– Augusto Vasques
what is this here?
onClick="return validar()"
– Augusto Vasques
PS: Text of the question and formatted with markdown
– Augusto Vasques
It’s to validate whether something was typed or n
– Lucas
PS: I am a beginner
– Lucas
Is there an error message, strange behavior, or is there anything else you’d like to comment on? Usually who responds PHP client/server makes desktop test is a fully human job, the more information about program behaviors and logs the better to respond.
– Augusto Vasques
Does not point out any errors, simply the content of the input whose name="phone" does not write to the bank, the rest of the code is working perfectly.
– Lucas
Maybe it’s a bug
– Lucas
That’s why, on top, I asked you to put in question the code of
validar()
.Most errors brought here occur during validation.– Augusto Vasques