php does not save form data

Asked

Viewed 34 times

0

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <title>Login Test</title>
    <link rel="shortcut icon" href="">
    <link rel="stylesheet" type="text/css" href="../css/style.css">
    <link href="https://fonts.googleapis.com/css?family=Share+Tech" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
</head>
<body id="pagina-login">
    <section>
        <div id="container-login">
            <div id="container-contorno-imagem">
                <!-- Contorno do USER FACE -->
            </div>
            <div id="container-imagem">
                <picture>
                    <img class="user-image" src="boy.svg">
                    <!-- (1o1) <img class="user-image" src="http://frankrausch.com/img/fr-1000px.jpg" alt="user face">  -->
                </picture>
            </div>
            <form name="cadastra" method="post" action="processa.php">
                <div id="container-email">
                    <span class="span-text"><em><b>Email:</b></em></span>
                    <input type="text" name="email" id="email" placeholder="Write your email">
                </div>
                <div id="container-username">
                    <span class="span-text"><em><b>User:</b></em></span>
                    <input type="text" name="nome" id="username" placeholder="Write your user name">
                </div>
                <div id="container-password">
                    <span class="span-text"><em><b>Password:</b></em></span>
                    <input type="password" name="senha" id="password" placeholder="Write your password">
                </div>
                <input type="submit" value="cadastrar" onclick="return cadastrando();">
            </form>
        </div>
        <a href="index.html" id="return"><i class="fas fa-undo-alt"></i></a>
        <!-- <a href="#" id="submit"><b>Submit</b></a> -->
    </section>
    <script type="text/javascript">
        function cadastrando(){
            var formulario = document.forms["cadastra"];

            var nome = cadastra.nome.value;
            var senha = cadastra.senha.value;
            var email = cadastra.email.value;

            if (nome == "") { alert("Preencha o campo de nome"); return false}
            if (senha == "") { alert("Preencha o campo de senha"); return false}
            if (email == "") { alert("Preencha o campo de email"); return false}
        }   
    </script>
</body>
</html>

<?php
$servidor = "localhost";
$usuario = "root";
$senha = "";
$dbname = "cadastro";

    $conn = mysqli_connect($servidor, $usuario, $senha, $dbname) or die (mysqli_error());

?>

<?php
    include_once("conexao.php");

    $nome = filter_input(INPUT_POST,'nome',FILTER_SANITIZE_STRING);
    $senha = filter_input(INPUT_POST,'senha',FILTER_SANITIZE_STRING);
    $email = filter_input(INPUT_POST,'email',FILTER_SANITIZE_EMAIL);

    $result_usuario = "INSERT INTO usuarios('nome', 'senha', 'email') VALUEs('$nome', $senha, '$email', NOW())";
    mysqli_query($conn, $result_usuario);
?>
  • You can put the column names without quotation marks and the values between quotation marks: "INSERT INTO usuarios(nome, senha, email) VALUEs('$nome', '$senha', '$email', NOW())"... I’m just not sure of the question of NOW().

  • I use PDO, but I think the problem is that it has 4 values and only 3 columns, NOW() is without column.

  • @Louie Well observed.

No answers

Browser other questions tagged

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