0

I'm making a sign up page and I need to insert the values on the database:

code:

<?php
    include 'config.php';
    $nome = $_POST['nome'];
    $sobrenome = $_POST['sobrenome'];
    $email = $_POST['email'];
    $ocupacao = $_POST['ocupacao'];
    $senha = $_POST['senha'];
    $senha2 = $_POST['senha2'];
    $emailkey = md5(microtime().rand());
    $ativo = 0; 
    $db = new PDO('mysql:host=localhost;dbname=sdpa;charset=utf8mb4', $user, $pass);

    $checemail = $db->prepare("SELECT * FROM  usuarios WHERE Email = :email");
    $checemail->bindParam(':email', $email, PDO::PARAM_STR);
    $checemail->execute();

    if ($checemail->rowCount() > 0) {
        //email already cadastred
    } else {
        $qr = $db->prepare("INSERT INTO usuarios(Nome, Sobrenome, Email, Ocupacao, Senha, EmailKey, Ativo) VALUES(?, ?, ?, ?, ?, ?, ?)");
        $qr->bindParam(1, $nome, PDO::PARAM_STR);
        $qr->bindParam(2, $sobrenome, PDO::PARAM_STR);
        $qr->bindParam(3, $email, PDO::PARAM_STR);
        $qr->bindParam(4, $ocupacao, PDO::PARAM_STR);
        $qr->bindParam(5, $senha, PDO::PARAM_STR);
        $qr->bindParam(6, $emailkey, PDO::PARAM_STR);
        $qr->bindParam(7, $ativo, PDO::PARAM_STR);
        $qr->execute();

        mail($email, "Chave de Ativacao", "Olá, obrigado por se registrar no SDPA, para ativar a sua conta, entre no link \n http://localhost/register_final?key=" + $emailkey + "", "Chave De Aticavao");
        echo "" + $emailkey;
    }

    $db = null;
?>

But, in the DB, the php inserts this:

aea3001cbe1aae38e0768b4d2d304c67

And, in the echo and the email, it shows this:

0

tlckpl
  • 59
  • 1
  • 8
  • Which column is getting this value? – Phiter Nov 22 '16 at 23:20
  • 2
    in php, the concatenation sign is ```.``` not ```+``` so in your mail it should be ```l?key=" . $emailkey``` Cf. http://php.net/manual/en/language.operators.string.php – olibiaz Nov 22 '16 at 23:21

1 Answers1

2

In PHP you'll want to use a period, or shortstop, (.) to concat strings (unlike Javascript that uses a plus (+)). - String Operators

Daerik
  • 4,167
  • 2
  • 20
  • 33