Page does not receive and does not register data in Mysql

Asked

Viewed 136 times

1

I’m mounting a php application for user registration, but for some reason when I input the data and click register, it reloads the page does not give any error, and does not load anything in the database.

    <?php
    $page_title = 'Registra Usuario';
    include ('includes/header.html');

    if (isset($_POST['submitted'])) {
        require_once ('includes/conexao.php');

        $erros = array();

        if (empty($_POST['p_nome'])) {
            $empty[] = 'Você esqueceu de digitar seu primeiro nome.';
        } else {
            $un = mysqli_real_escape_string($dbc, trim($_POST['p_nome']));
        }

        if (empty($_POST['u_nome'])) {
            $empty[] = 'Você esqueceu de digitar seu ultimo nome.';
        } else {
            $pn = mysqli_real_escape_string($dbc, trim($_POST['u_nome']));
        }

        if (empty($_POST['email'])) {
            $empty[] = 'Você esqueceu de digitar seu email.';
        } else {
            $e = mysqli_real_escape_string($dbc, trim($_POST['email']));
        }

        if (!empty ($_POST['pass1'])) {
            if ($_POST['pass1'] != $_POST['pass2']) {
                $erros[] = 'Seu password não corresponde a confirmação.';
            } else {
                $p =   $un = mysqli_real_escape_string($dbc, trim($_POST['pass1']));
            }
        } else {
            $erros[] = 'Você esqueceu de digitar seu password.';
        }

        if (empty($erros)) {
            $q = "INSERT INTO usuario (p_nome, u_nome, email, pass, data_reg) VALUES ('$pn', '$un', '$e', SHA1('$p'), NOW())";

            $r = @mysqli_query($dbc, $q);

            if ($r){
                echo '<h1> Obrigado!</h1>
                <p> Agora você está registrado</p>
                <p><br /></p>';
            } else {
                echo '<h1> Erro no Sistema </h1>
                      <p class=""error"> você não pôde ser registrado devido a um erro do sistema.
                      Pedimos desculpa por qualquer inconveniente</p> ';
                echo '<p>' . mysqli_error($dbc).
                     '<br /> <br/> Query: ' . $q . '</p>';    
            }
            mysqli_close($dbc);
            include('includes/footer.html');
            exit();
        } else {
            echo '<h1>Erro!</h1> <p class="error">Ocorreram os seguinte(s)erro(s): <br /> ';

            foreach ($erros as $msg ){
                echo " - $msg<br />\n";
            }
            echo '</p><p> Por favor, tente novamente. </p><p><br /></p>';
        }
        mysqli_close($dbc);
    }
    ?>

  <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
    $(document).ready(function(){
        $("#teste").click(function(e){
            e.preventDefault();
            console.info($("#myform").serialize());
            console.info($("#teste").val())
        });
    });

</script>

        <h1> Registrar Usúario</h1>
        <form action="registro.php" method="post" id="myform">
            <p> Primeiro Nome: <input type="text" name="p_nome" size="15" maxlength="20"
            value="<?php if (isset($_POST['p_nome'])) echo trim ($_POST['p_nome']); ?>" /> </p>

            <p> Último Nome: <input type="text" name="u_nome" size="15" maxlength="40"
            value="<?php if (isset($_POST['u_nome'])) echo trim ($_POST['u_nome']); ?>" /> </p>

            <p> Email: <input type="text" name="email" size="15" maxlength="80"
            value="<?php if (isset($_POST['email'])) echo trim ($_POST['email']); ?>" /> </p>

            <p>Senha: <input type="password" name="pass1" size="10" maxlength="20" /> </p>
            <p>Confirmação de Senha: <input type="password" name="pass2" size="10" maxlength="20" /> </p>

            <p><input type="submit" name="submit" value="Registrar" id="teste" /></p>

            <input type="hidden" name="submitted" value="TRUE"/>
        </form>

I added this jquery code to see if they were passing values and the result was :

inserir a descrição da imagem aqui

  • Just for the record, there are extra quotes here: <p class=""error"> - One thing you have to take care of, is to show neither the query nor the errors to the end user. The ideal is to write to a log and only warn that the application had an unexpected problem.

  • If there is an error with the query, the @ will cause them to be ignored. The line $p = $un = mysqli_ [...]; is really what you want?

  • @Berriel is what I want

  • @Bacco the intention is to show even, but thanks for the tips.

  • @Guilhermelima is sure you want the $un, which must be the username, is equal to pass1?

  • @Barriel was a typo it was only supposed to be $p

Show 1 more comment

2 answers

0

Cara checks if the connection is open in the file, tries to run the SELECT NOW() command must display the date and time, if not, of an echo of the query ($q) and tries to run directly in your database if no error is reported again

  • I put the now() under the mysqli_close($dbc); it does not show the time..

0

If there are no errors, it is because your query is not running. Perform a manual Insert query and see if any error is returned with mysli_error.

Browser other questions tagged

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