Registration problem using PDO

Asked

Viewed 96 times

0

I am creating a simple PDO registration system (I am beginner in this), and, I am not having success in designing my connection string and adjusting INSERT to add data to the database.

Gives the following error:

Notice: Undefined variable: PDO in /opt/lampp/htdocs/KELVYN/New/cadastro_2.php on line 23

Connection file.php

define("HOST", "localhost");
define("USER", "root");
define("PASS", "");
define("BD", "kelvyn");

try{

    $conecta    = new PDO('mysql:host='.HOST.';dbname='.BD, USER, PASS);

}catch(PDOException $e){

    echo 'Erro ao conectar com o MySQL: ' . $e->getMessage();

}

Register file_2.php

$dados = filter_input_array(INPUT_POST);

if(!empty($dados)){

if($conecta){

    #$erro  = "Ocorreu o Seguinte erro: ".mysql_error()." | Código do erro: ".mysql_errno();
    $query  = "INSERT INTO clientes(cliente,cpf,idt,data,plano,vencimento,endereco,bairro,cidade,estado,cep,login,senha,email,tel_fixo,tel_cel,referencia,aceita_termos_contrato,obs) VALUES (:cliente,:cpf,:idt,:data,:planos,:vencimento,:endereco,:bairro,:cidade,:estado,:cep,:login,:senha,:email,:tel_fixo,:tel_cel,:referencia,:aceito-contrato)";
    $stmt = $PDO->prepare($query);
    $stmt->bindParam( ':cliente', $dados["cliente"] );
    $stmt->bindParam( ':cpf', $dados["cpf"] );
    $stmt->bindParam( ':idt', $dados["idt"] );
    $stmt->bindParam( ':data', $dados["data"] );
    $stmt->bindParam( ':plano', $dados["plano"] );
    $stmt->bindParam( ':vencimento', $dados["vencimento"] );
    $stmt->bindParam( ':endereco', $dados["endereco"] );
    $stmt->bindParam( ':bairro', $dados["bairro"] );
    $stmt->bindParam( ':cidade', $dados["cidade"] );
    $stmt->bindParam( ':estado', $dados["estado"] );
    $stmt->bindParam( ':cep', $dados["cep"] );
    $stmt->bindParam( ':login', $dados["login"] );
    $stmt->bindParam( ':senha', $dados["senha"] );
    $stmt->bindParam( ':email', $dados["email"] );
    $stmt->bindParam( ':tel_fixo', $dados["tel_cel"] );
    $stmt->bindParam( ':referencia', $dados["referencia"] );
    $stmt->bindParam( ':aceita_termos_contrato', $dados["aceita_termos_contrato"] );
    $stmt->bindParam( ':obs', $dados["obs"] );

    $result = $stmt->execute();

    if(!$result){
        var_dump( $stmt->errorInfo() );
        exit;
        #header("location: thanks.php");
    }
    header("location: thanks.php");
}

}
  • Welcome to Sopt Network, I suggest you do a [tour] first of all :) ?

  • Perhaps your mistake is here: $stmt = $PDO->prepare($query); change to $stmt = $conecta->prepare($query);

  • Dear Friend, thank you so much! That’s right. Line 23 was this same $PDO. Solved, but I had another problem now. Warning: Pdostatement::execute(): SQLSTATE[HY093]: Invalid Parameter number: Parameter was not defined in /opt/lampp/htdocs/KELVYN/New/cadas_2.php on line 43 This is it: $result = $stmt->execute();

  • In their VALUES, foul :obs

  • Thank you so much! I identified a number of mistakes I made. I’m still having problems. Still, I really liked PDO.

  • I managed to solve all the problems! Thank you very much, friend!

Show 1 more comment
No answers

Browser other questions tagged

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