0

Hello here is the code to import categories, but something bad

error: 

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'kategorijos(name, desc, ordering, visibility, allowcomm, allowads) VALUES([' at line 2' in /home/u410366608/public_html/admin/categories.php:136 Stack trace: #0 /home/u410366608/public_html/admin/categories.php(136): PDOStatement->execute(Array) #1 {main} thrown in /home/u410366608/public_html/admin/categories.php on line 136

code: `elseif ($do == 'Insert') {

        if ($_SERVER['REQUEST_METHOD'] =='POST') {

            echo "<h1 class='text-center'>Prideti kategorija.</h1>";
            echo "<div class='container'>";

            $name       = $_POST['name'];
            $desc       = $_POST['description'];
            $order      = $_POST['ordering'];
            $visible    = $_POST['visibility'];
            $comment    = $_POST['commenting'];
            $ads        = $_POST['ads'];            

            $check = checkItem("name", "kategorijos", $name);

                if ($check == 1) {
                    echo "<div class='container'>";
                    $theMsg = '<div class="alert alert-danger">Tokia kategorija jau yra.</div>';
                    redirectHome($theMsg, 'back' );
                    echo "</div>";
            }

            else {

                $stmt = $con->prepare("INSERT INTO kategorijos(name, desc, ordering, visibility, allowcomm, allowads)
                VALUES([:zname], [:zdesc], [:zorder], [:zvisible], [:zcomment], [:zads])");

                $stmt->execute(array(

                    'zname'     => $name,
                    'zdesc'     => $desc,
                    'zorder'    => $order,
                    'zvisible'  => $visible,
                    'zcomment'  => $comment,
                    'zads'      => $ads



                ));

                echo "<div class='container'>";
                $theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . 'Kategorija prideta.</div>';
                redirectHome($theMsg, 'back' );
                echo "</div>";
            }


    }

            else {
                echo "<div class='container'>";

                $theMsg = '<div class="alert alert-danger">Neturite siam puslapiui teisiu.</div>';
                redirectHome($theMsg, 'back');

                echo "</div>";

                }
            echo "</div>";


        }`

pls help

Eimantas
  • 11
  • 1
  • `desc` is a reserved word –  Dec 08 '16 at 21:11
  • In your query you have $stmt = $con->prepare("INSERT INTO kategorijos(name, desc.......); You need to change your column name to description, as desc (DESC) is a reserved word and cannot be used. You could work around this by using back-ticks for your column names: eg."INSERT INTO kategorijos( `name`, `desc`........); but this is not a substitute for a good naming convention. – Kevin Waterson Dec 08 '16 at 21:26

0 Answers0