-2
I am making a form in php ,but he does not want to add the data in the database, can you see what is wrong? is not generating any error.
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>CRUD - Cadastrar</title>
*********************************************************************************************
<?php
session_start();
include_once("conexao.php");
$nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
$telefone = filter_input(INPUT_POST, 'telefone', FILTER_SANITIZE_STRING);
$cpf = filter_input(INPUT_POST, 'cpf', FILTER_SANITIZE_STRING);
$endereco=$_POST["endereco"];//atribuição do campo"endereco"vindo do formulário para variavel
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$result_usuario = "INSERT INTO cadastro2(nome,telefone,cpf,endereço, email, created) VALUES ('$nome','$telefone','$endereco,'$cpf','$email', NOW())";
$resultado_usuario = mysqli_query($conn, $result_usuario);
if(mysqli_insert_id($conn)){
$_SESSION['msg'] = "<p style='color:green;'>Usuário cadastrado com sucesso</p>";
header("Location: index.php");
}else{
$_SESSION['msg'] = "<p style='color:red;'>Usuário não foi cadastrado com sucesso</p>";
header("Location: index.php");
}
*******************************************************************************************
<?php
$servidor = "localhost";
$usuario = "root";
$senha = "";
$dbname = "cadastro";
//Criar a conexao
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
if (!$conn) {
}
</head>
<body>
<h1>Cadastrar Usuário</h1>
<?php
if(isset($_SESSION['msg'])){
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
?>
<form method="POST" action="processa.php">
<label>Nome: </label>
<input type="text" name="nome" placeholder="Digite o nome completo"><br><br>
<label>Telefone: </label>
<input type="Telefone" name="Telefone" placeholder="Digite o seu telefone"><br><br>
<label>CPF: </label>
<input type="CPF" name="CPF" placeholder="Digite o seu CPF"><br><br>
<label>Endereço: </label>
<input type="Endereço" name="Endereço" placeholder="Digite o seu endereço"><br><br>
<label>E-mail: </label>
<input type="email" name="email" placeholder="Digite o seu melhor e-mail"><br><br>
<input type="submit" value="Cadastrar">
</form>
</body>
</html>
But where’s the file
processa.php
? Without it there is no way to know why data is not saved.– Augusto Vasques
$result_usuario = "INSERT INTO cadastre 2(name,phone,Cpf,address, email, created) VALUES ('$name','$phone','$address,'$Cpf','$email', NOW()"; $resultado_usuario = mysqli_query($Conn, $result_usuario); if(mysqli_insert_id($Conn)){ $_SESSION['msg'] = "<p style='color:green;'>Successfully registered user</p>"; header("Location: index.php"); }Else{ $_SESSION['msg'];}
– Gabriel Reymes
Edit and ask by pressing the button edit and put this information into the body of the question.
– Augusto Vasques