ERROR WHEN INSERTING PHPMYADMIN

Asked

Viewed 77 times

-3

arquivo de conexo

Ãrquivo de inserir no banco

does not insert any information in the database from the error below:

Fatal error: Uncaught Error: Call to a Member Function prepare() on null in C: xampp htdocs LOGIN SCREEN classes videos.php:11 Stack trace: #0 C: xampp htdocs LOGIN SCREEN php addGaleria.php(25): Videos->register('escola_online', '127.0.0.1', 'root', ') #1 {main} thrown in C: xampp htdocs LOGIN SCREEN classes videos.php on line 11

  • The values are going without Quotes to the bank, can’t that be the problem? because they are strings

  • so I put it but still, it doesn’t insert!

  • but the error does not yet insert in the bank!!!

  • bindValue is with single quotes too

  • debug it, print the string it creates with VAR_DUMP() and ask the question

1 answer

-3


Following the PHP Handbook you can see that the Insert with bindValue uses simple quotes, I believe this is impacting your code. Thus remaining:

<?php
  Class videos
  {
     try{

          $pdo = new PDO('mysql:host=localhost;dbname=meuBancoDeDados', $username, $password);
           $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        public function cadastrar($titulo, $thumb, $descricao, $idVid)
        {
       $sql = $pdo-> prepare("INSERT INTO video(titulo, thumb, descricao, embed) VALUES (':t',':th',':d',':vi')");
       $sql->execute(array(
              ':t'=> $titulo,
              ':th' => $thumb,
              ':d' => $descricao,
              ':vi' => $idVid
       ));
      }

       echo $sql->rowCount();
     }
     catch(PDOException $e) {
          echo 'Error: ' . $e->getMessage();
        }
  }   
?>

I added a PDO connection assuming I did it on your code but not posted, if not, the problem may be there

  • I tested what happened to me and I didn’t succeed, that strange I have the other one that is working ok this will not at all

  • Could you insert another by sinking the error it shows? Debugging with var_dump and seeing if it is really inserting what you want and pasting in the database to see if you are having a syntax error or something like that

  • <?php Class videos { Try{ $Pdo = new PDO('mysql:host=localhost;dbname=escola_online', $embed, $title); $Pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); public Function register($title, $Thumb, $Description, $idVid) { $sql = $Pdo-> prepare("INSERT INTO video(title, Thumb, Description, embed) VALUES(':t',':th',':d',':vi')"); $sql->execute(array( ':t'=> $title, ':th' => $Thumb, ':d' => $Description, ':vi' => $idVid )); }?>

  • I am new with php I could not debug, if I can help I thank you so much so I learn.

Browser other questions tagged

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