Jump to content
Fórum Script Brasil
  • 0

Call to a member function prepare() on null


GabiGui
 Share

Question

Olá pessoal, meu sistema de postagens está dando o erro Call to a member function prepare() on null na linha 54. Alguém sabe como resolver? 

Segue abaixo o código.

<!DOCTYPE>
<?php 
      include_once '_php/BD.class.php';
      global $conn;
?>
<html>
    <head>
        <title>Postagens</title>
    </head>
    <body>
        <?php
        ini_set('display_errors', true);
        error_reporting(E_ALL);
        ?>
        <form name="entrar" method="post" action="#">
           
            <label>
                <textarea type="text"name="texto" cols="22" rows="6" id="textoPostagem"></textarea>
            </label>
            <br/>
            <input type="submit" name="postar" value="Postar">
            <br/>
        </form>

    <form method="post" action="_php/recebe_upload.php" enctype="multipart/form-data">
  <label>Arquivo</label>
  <input type="file" name="arquivo" />
  
  <input type="submit" value="Enviar" />
</form>

        <?php
  
         
      
?>

        <?php
       if(isset($_POST['postar']) && empty($_POST['textoPostagem'])){
        $post = $_POST['texto'];
        $data = date("Y/m/d");
        if (strlen($_POST['texto'])) {
            
            //$sql = "INSERT INTO mydb (postagens) VALUES('$post')";
            $sql = $conn->prepare("insert into mydb (postagens) values ('$post')");
            $sql->bind_param(1, $post);
            $sql->execute() or exit(print_r($sql->errorInfo(), true));; 
            $stmt2 = $conn->prepare("select postagens from postagens");
            $stmt2->execute();

            while ($stmt2->fetch(PDO::FETCH_OBJ)) {

                /* ($exibir = mysqli_fetch_array($executar))
                  echo $exibir['texto'];
                  echo " "; */
                $nome=$reg->nome;
                echo $nome;
                echo $reg->texto;
                echo $date;
            }
            
        }
        } else {
            echo "Digite um texto";
        }

       

    </body>

</html>

Código da conexão com BD

<?php 
	class BD{
		private static $conn;
		static function getConn(){
			if (is_null (self::$conn)) {
				self::$conn = new PDO('mysql:host=localhost;dbname=mydb','root','');
				
			}
			return self::$conn;
			
		}
		
	}
	

?>

Agradeço desde já a ajuda. 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...