How to enter data of a form in the bank

1

Hello

I created the code below and when I execute it inserts a record in the database, but does not enter the data entered in the form. Can anyone help me?

the screen displays the message: Invalid Query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES)' at line 1

    class Banco {

        //parametros de configuração de banco

        protected static $servidor = "localhost";
        protected static $usuario = "root";
        protected static $senha = "root";
        protected static $esquema = "mapa";

        //conexao com banco

        public function conectar() {
            $db = mysqli_connect(self:: $servidor, self:: $usuario, self::  $senha, self::$esquema);
            if (!$db) {
                die('Não foi possivel conectar: ' . mysqli_error());
            }
            return $db;
        }// fim conectar


        //desconexão com banco

        public function desconectar($db) {
             mysqli_close($db);
        }//fim desconectar

            public function salvar() {
            $campos = get_object_vars($this);
            $sqlI = "INSERT INTO " . get_class($this) . " (";
            $sqlF = ") VALUES (";
            foreach ($campos as $key => $value) {
                $sqlI.= $key . ",";
                if (!is_object($campos[$key])) {
                    $sqlF.= "'" . $value . "',";
                } else {
                    $sqlF.= "'" . $campos[$key]->getId() . "',";
                }
            }//fim foreach
            $sql = substr($sqlI, 0, strlen($sqlI) - 1) . substr($sqlF, 0, strlen($sqlF) - 1) . ")";
            $db = $this->conectar();
            $res = mysqli_query($db, $sql);
            if (!$res) {
                die('Query inválida: ' . mysqli_error($db));
            }
            $id = mysqli_insert_id($db);
            $this->desconectar($db);
            return $id;
        }//fim salvar

Thank you in advance

    
asked by anonymous 19.03.2016 / 02:16

0 answers