-2

ı'm using a code block which ı already used in a different insert data process, but ı don't know why, it doesn't work. it sends me contact.php?in=error. what is the problem with my codes?

<?php 

if(@$_POST['submit']){

    $gizlicap = $_POST['hcaptcha'];
    $code = $_POST['captcha'];

    if($code == $gizlicap){
        $name = htmlspecialchars($_POST['ad'], ENT_QUOTES, 'utf-8');
        $email = htmlspecialchars($_POST['eposta'], ENT_QUOTES, 'utf-8');
        $yazi = htmlspecialchars($_POST['text'], ENT_QUOTES, 'utf-8');

        $snd = $db->prepare("INSERT INTO `contactform` (`message_id`, `message_ad`, `message_email`, `message`) VALUES (NULL, :ad, :email, :yazi) ");
        $snd->bindValue(":ad", $name, PDO::PARAM_STR);
        $snd->bindValue(":email", $email, PDO::PARAM_STR);
        $snd->bindValue(":yazi", $yazi, PDO::PARAM_STR);

        if($snd->execute()) {
            @header("Location: contact.php?in=success");
        } else {
            @header("Location: contact.php?in=error");
        }
    } else {
        echo 'Check security code!!';
    }
}
?>
Barmar
  • 741,623
  • 53
  • 500
  • 612
Kimse
  • 41
  • 1
  • 6

1 Answers1

-1

Do you have $db variable definied? Use try-catch instruction to handle exceptions, so you'll get message what is wrong.

  • 1
    It makes no sense to use try-catch instruction to handle exceptions, because exceptions report themselves – Your Common Sense May 11 '20 at 09:52
  • yes ı have $db variable and same code is working when ım trying to add blog essey into table... I seriously can't understand what is problem – Kimse May 11 '20 at 13:16
  • ı forgot to make id column autoincrement, so thats why codes didn't work. Thank you all – Kimse May 11 '20 at 19:08