I can’t do the insert in the bank

Asked

Viewed 37 times

-2

I made this code to register a client in a website db. The code is coming back as if the field is empty.

Can someone tell me if I’ve done something wrong??

PHP

session_start();
include('conect.php');

// RECEBE O SINAL DO BOTAO
if(isset($_POST['btn_cad_cli'])){

    // CHECA SE OS CAMPOS FORAM PREENCHIDO 
    if(empty($_POST['nome_cli']) || empty($_POST['sobnome_cli']) || 
    empty($_POST['email_cad_cli']) || empty($_POST['senha_cad_cli'])) {

        // SE NAO. VOLTA PARA A PAGINA E ENCERRA SESSAO
        Header('Location: ../cadastro_cli.php');
        exit();
    }else{

        // CRIA AS VARIAVEIS
        $nome = htmlentities($_POST['nome_cli']);
        $sobNome = htmlentities($_POST['sobnome_cli']);
        $email = htmlentities($_POST['email_cad_cli']);
        $senha = htmlentities($_POST['senha_cad_cli']);

        // DA UM INSERT NA TABELA
        $mysqli->query("insert into login_cli values('','$nome','$sobNome','$email','$senha')");
        echo $mysqli->error;

        if ($mysqli->num_rows > 0){

            Header("Location:../index.php");
            exit();
        }else{
         Header('Location: ../cadastro_cli.php');
        exit();
        }

    }

}   

?>

  • Well, the first field of values SQL is empty. Why?

  • This is the field where you will generate the table ID. this as auto_increment

  • It is not better to specify default in the first field? "insert into login_cli values(DEFAULT, '$nome', '$sobNome', '$email', '$senha')"

1 answer

1

My suggestion is you use sending by means of parameters mainly because it will suffer with sqlinjection in the mode being done but, keeping as you are wishing to do, try so:

$mysqli->query("insert into login_cli (nome, sobnome, email, senha) values(".$nome.",".$sobNome.",".$email.",".$senha.")");

Browser other questions tagged

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