Confirm registration by email - PDO

Asked

Viewed 42 times

-1

I am trying to make a confirmation of registration by email, but I am not succeeding. I can get the user, email and password. but when I echo the $id and $md5 variable to check the data nothing appears and INSERT is not done. Follow the code.

<?php
$host = "mysql:busca;host=localhost";
$usuario = "root";
$pass = "";

try{
    $pdo = new PDO($host, $usuario, $pass);
}catch(PDOExecption $e){
    echo "Falha: ". $e->getMessage();
}

$user = addcslashes($_POST['user'],"F");
$email = addcslashes($_POST['email'],"F");
$senha = md5(addcslashes($_POST['senha'],"F"));

$pdo->query("INSERT INTO tabela1 SET user='$user', email='$email', senha='$senha'");

$id = $pdo->lastInsertId();
$md5 = md5($id);

$assunto = "Confirme seu cadastro";
$link = "confirma.php?h=".$md5;
$mensagem = '<a href="'.$link.'">Clique aqui para confirmar: </a>';
$header = "From: teste";

echo $user.'<br>';
echo $email.'<br>';
echo $senha.'<br>';
echo $id.'<br>';
echo $md5.'<br>';
mail($email, $assunto, $mensagem, $header);


?>

Table:

CREATE TABLE `tabela1` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `user` varchar(50),
  `email` varchar(100),
  `senha` varchar(50),
  `status` tinyint(4)
);

1 answer

0

That line is incorrect

$host = "mysql:busca;host=localhost";

the correct is

$host = "mysql:host=localhost;dbname=busca";

Browser other questions tagged

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