Help with SQL and PHP

Asked

Viewed 27 times

-2

Good afternoon, I need a help, I’m beginner in php

I have the following code that works and sends the e-mail all right.

<?php

$host    = "mysql:dbname=agendamentos;host=phpmyadmin.srv-45-34-12-242.hostoo.io";
$usuario = "agendamento";
$pass    = "#####";

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

$email    = "[email protected]";
$assunto  = "Email Teste";
$mensagem = "teste de email enviado com php e sql";
$header   = "from: victor teste";

mail($email, $assunto, $mensagem, $header);

?>

But when I try to put some variable to search the database I can’t get it to stop sending the emails, follows the way I’m trying to do.

<?php

$host    = "mysql:dbname=agendamentos;host=phpmyadmin.srv-45-34-12-242.hostoo.io";
$usuario = "agendamento";
$pass    = "####";

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

$buscaemail="select email from clientes where id=103";

$email    = "$buscaemail";
$assunto  = "Email Teste";
$mensagem = "teste de email enviado com php e sql";
$header   = "from: victor teste";

mail($email, $assunto, $mensagem, $header);

?>

Thanks so much, thanks so much!

  • Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativities worth reading the Stack Overflow Survival Guide in English.

1 answer

0


<?php

$host    = "mysql:dbname=agendamentos;host=phpmyadmin.srv-45-34-12-242.hostoo.io";
$usuario = "agendamento";
$pass    = "####";

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

$consulta="select email from clientes where id=103";
$buscaemail = $pdo->query($consulta)->fetchColumn();

$email    = "$buscaemail";
$assunto  = "Email Teste";
$mensagem = "teste de email enviado com php e sql";
$header   = "from: victor teste";

mail($email, $assunto, $mensagem, $header);

?>

Browser other questions tagged

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