I am using Pdo prepare statement appears no error and neither enters anything in the database

Asked

Viewed 56 times

0

index php.

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

php bank.

<?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();
        }
    }
?>
  • Wait I already put the question of ours, I’m new here .

1 answer

0


The syntax of Insert is wrong. She should be something for example:

INSERT INTO NOME_DA_TABELA (CAMPOS_QUE_DESEJA_INSERIR_DADOS) VALUES (VALORES_DOS_CAMPOS).

What was typed in the question was a similar one 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)");
  • thanks for the reply Israel Zebulon but it still didn’t work

  • thanks for the help Israel Zebulon worked, had also a table writing error

Browser other questions tagged

You are not signed in. Login or sign up in order to post.