插入查询pdo不会在数据库中插入数据

时间:2016-03-10 10:07:50

标签: php mysql pdo

我正在开发一个项目,现在我正在制作一个帖子系统,所以注册用户可以在网站上发表评论,但如果我尝试使用我的插入查询插入数据,它就不会将数据插入到数据库中。所以如果有人可以帮我解决这个问题。

    <head>
    <script src="ckeditor/ckeditor.js"></script>
</head>
<form action="" method="post">
    <strong>Bericht :</strong><input type="text" name="bericht"><br />
    <strong>Content :</strong><textarea cols="50" rows="10" name="content"></textarea><br />

    <script type='text/javascript'>
        CKEDITOR.replace('content',
            {
                width: 500,
                height: 250
            });
    </script>
    <p>* Required</p>
    <input type="submit" name="submit" value="Submit">
</form>
<?php

include_once "db.php";
include "repeatForm.php";



if (isset($_POST['submit'])) {
    if ($_POST['bericht'] == '' || $_POST['content'] == '') {
        $error = "Niet alle velden waren ingevuld";
        repeatForm($error, '', '');
    } else {
        $insert = $dbcon->prepare("INSERT INTO pages (berichtNaam, paginaContent) VALUES (:berichtNaam, :content)");
        $insert->bindParam(":berichtNaam", $_POST['bericht'], PDO::PARAM_STR);
        $insert->bindParam(":content", $_POST['content'], PDO::PARAM_STR);
        $insert->execute();

        header("Location: http://127.0.0.1/nieuws/index.php");
        exit;
    }
}

?>

这是数据库连接:

    <?php

    try {
        $dbcon = new PDO('mysql:host=localhost;dbname=register', 'root', '');
    $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }   catch(PDOException $e) {
        echo $e->getMessage();
        die();
    }
    ?>

and here the repeatForm:

<?php
function repeatForm() {
    echo "
    <form method='post' action='".$_SERVER['PHP_SELF']."'>
    <input type='hidden' name='id' />
     <input style='font-size: 2.5rem' type='text' name='cTitle' >
    <textarea  name='ed1' cols='50' rows='10' ></textarea>


    <script>

    CKEDITOR.replace('ed1',
            {
                toolbar:[
                    { name: 'document', items: [ 'Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates' ] },
                    { name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
                    { name: 'editing', items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
                    { name: 'forms', items: [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
                    '/',
                    { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
                    { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language' ] },
                    { name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
                    { name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe' ] },
                    '/',
                    { name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
                    { name: 'colors', items: [ 'TextColor', 'BGColor' ] },
                    { name: 'tools', items: [ 'Maximize', 'ShowBlocks' ] },
                    { name: 'about', items: [ 'About' ] }
                ],
                width: 600,
                height: 200
            });


    </script>
    <input type='submit' Name='submit' value='Post'><input type='submit' name='cancel' value='cancel'>
    </form> ";
}


?>

我收到此错误:

  

致命错误:带有消息'SQLSTATE [42000]的未捕获异常'PDOException':语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在Z:\ sites \ nieuws \ create.php中的第1行'

Hallo

)附近使用正确的语法:34 Stack跟踪:#0 Z:\ sites \ nieuws \ create.php(34):PDOStatement-&gt;执行()#1 {main}在第34行的Z:\ sites \ nieuws \ create.php中抛出

0 个答案:

没有答案
相关问题