Error when registering data in the database

Asked

Viewed 36 times

0

I’m having a hard time getting some data into the database. When I click to register the message appears at the end of the code "error when registering". I’ve reviewed the code and I’ve reviewed the code almost completely and I can’t get a solution in, can anyone give me a hint ?

 if(isset($_POST['cadastrar']) && $_POST ['cadastrar'] == "register")

{ $name = $_POST['name']; $surname = $_POST['surname']; $data = $_POST['date']; $Cpf = $_POST['Cpf']; $email = $_POST['email']; $pais = $_POST['pais']; $status = $_POST['status']; $login = $_POST['login']; $password = $_POST['password']; $rsenha = $_POST['rsenha'];

    if(empty($nome) || empty($sobrenome) || empty($data) || empty($cpf) || empty($email) ||  empty($pais) || empty($estado) || empty($login) || empty($senha) || empty($rsenha) || ($cpf_enviado == false) || (@$emailvalida == false))

  {

  }else{

            include_once("settings.php");
            $con = mysqli_connect("localhost","root","","bd_winfo");
            $query = "SELECT bd_winfo FROM cadastro WHERE login = '".$login."'";
            $cadastrar = "INSERT INTO cadastro (nome, sobrenome, data, cpf, email, pais, estado, login, senha, rsenha)
                    VALUES ('$nome', '$sobrenome', '$data', '$cpf', '$email', '$pais', '$estado', '$login', '$senha', '$rsenha')";
                if(mysqli_query($con, $query))
                {
                  $_SESSION['nome'] = $nome;
                  $_SESSION['sobrenome'] = $sobrenome;
                  $_SESSION['data'] = $data;
                  $_SESSION['cpf'] = $cpf;
                  $_SESSION['email'] = $email;
                  $_SESSION['pais'] = $pais;
                  $_SESSION['estado'] = $estado;
                  $_SESSION['login'] = $login;
                  $_SESSION['senha'] = $senha;  
                  $_SESSION['rsenha'] = $rsenha;          

                }
                else
                {
                  echo '<div id="preencha" style="width:200px; position:relative; left:580px; top:-30px; color:#fff; font-size:15px; ">Erro ao cadastrar!</div>';
                }
        }
  }
  • Dude, do a var_dump($register);Exit(); and see which return.

  • Take the result var_dump or echo and put in Mysql to see what happens, and it will return you the error

  • Warning: Your code has a high risk of Injection attacks, use PDO with bindParam. Never concatenate strings and run SQL.

  • And if you use variable inside the string you have to use double quotes "$name"

No answers

Browser other questions tagged

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