INSERT INTO不执行[重复]。

问题描述 投票:-1回答:1

ı正在使用一个代码块,ı已经在不同的插入数据过程中使用,但ı不知道为什么,它不工作。它向我发送 contact.php?in=error。

<?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!!';
    }
}
?>
php database pdo insert sql-insert
1个回答
-1
投票

你有定义$db变量吗?捉迷藏 指令来处理异常,这样你就会收到错误的信息。

© www.soinside.com 2019 - 2024. All rights reserved.