I am using pdo prepare statement does not appear error and does not enter anything in the database

0

index.php

<?php 
    require 'banco.php';
    $usuario = new usuario("localhost","blog","root","");
    $usuario -> inserir("dfd","[email protected]",123,"Ola mudfndo");
?>

banco.php

<?php 
    class usuario{
        private $pdo;
        public function __construct($host,$dbname,$dbusser,$dbpass){
            try {
                $this ->pdo = new PDO("mysql:dbname=".$dbname.";host=".$host,$dbusser,$dbpass);
            } catch (Exception $e) {
                echo "Falhou: ".$e->getMessage();
            }
        }
        public function inserir($nome,$email,$senha,$menssagem){
            $sql = $this ->pdo->prepare("INSERT INTO usuario SET nome =:nome,email =:email,senha =:senha,menssagem =:menssagem ");
            $sql ->bindParam(':nome',$nome);
            $sql ->bindParam(':email',$email);
            $sql ->bindParam(':senha',$senha);
            $sql ->bindParam(':menssagem',$menssagem);
            $sql ->execute();
        }
    }
?>
    
asked by anonymous 12.10.2017 / 10:13

1 answer

0

The syntax of the insert is wrong. It should be something like:

INSERT INTO NOME_DA_TABELA (CAMPOS_QUE_DESEJA_INSERIR_DADOS) VALUES (VALORES_DOS_CAMPOS).

What was typed in the question was similar to the UPDATE syntax:

$sql = $this ->pdo->prepare("INSERT INTO usuario SET nome =:nome,email =:email,senha =:senha,menssagem =:menssagem ");

So, change to:

$sql = $this ->pdo->prepare("INSERT INTO usuario (nome,email,senha,menssagem) values (:nome,:email,:senha,:menssagem)");
    
12.10.2017 / 11:16