-2
Hello, I am beginner in PDO and in my development of a form I can not send anything to the database and I can not identify the problem in my php form, someone could help me please?
FILE index.php(ex):
<?php session_start();?>
<input type="text" name="nome" data-required="true" placeholder="Nome*">
<input type="email" name="email" data-required="true" placeholder="Endereço de e-mail*">
<input type="text" name="assunto" data-required="true" placeholder="Assunto*">
<textarea name="message" data-required="true" placeholder="Message*"></textarea>
<button type="submit" name="SendCadCont">Enviar</button>
FILE send_mail.php(ex):
<?php
session_start();
$conn = new PDO("mysql:host=localhost;dbname=teste", "root", "root");
// Verificação do botão quando apertado.
$SendCadCont = filter_input(INPUT_POST, 'SendCadCont', FILTER_SANITIZE_STRING);
if ($SendCadCont) {
//Recebe os dados do formulário.
$nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING);
$assunto = filter_input(INPUT_POST, 'assunto', FILTER_SANITIZE_STRING);
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING);
//Insere os dados no DB
$result_msg_cont = "INSERT INTO msg (nome, email, assunto, message) VALUES (':nome', ':email', ':assunto', ':message')";
$insert_msg_cont = $conn->prepare($result_msg_cont);
$insert_msg_cont->bindParam(':nome', $nome);
$insert_msg_cont->bindParam(':email', $email);
$insert_msg_cont->bindParam(':assunto', $assunto);
$insert_msg_cont->bindParam(':message', $message);
if ($insert_msg_cont->execute()) {
$_SESSION['msg'] = 'Enviado';
header("location: email");
}else{
$_SESSION['msg'] = 'Não enviado';
header("location: email");
}
}else{
$_SESSION['msg'] = 'Problema';
header("location: email");
}
?>
... And even so it does not send the data to the database. I thank anyone who can help me.
Thank you very much, your concept uses mysql_connect and in the connection I was using PDO to have more security against SQL attacks(But it worked yes) Thank you very much.
– M4RC0SJS