Call to a member function query() on a non-object... [Résolu/Fermé]
Signaler
GidasGael
GidasGael
- Messages postés
- 3
- Date d'inscription
- samedi 23 janvier 2016
- Statut
- Membre
- Dernière intervention
- 8 février 2016
GidasGael
- Messages postés
- 3
- Date d'inscription
- samedi 23 janvier 2016
- Statut
- Membre
- Dernière intervention
- 8 février 2016
Bonjour,
Je suis bloqué depuis plusieurs heures sur un problème, j’essaye de convertir un tchat que j'avais fais en POO, il y a la page principale:
Une page qui traite les données:
Une page où il y a les classes:
Et là on m'affiche:
Call to a member function query() on a non-object in C:\wamp\www\Entrainement\tchat.class.php on line 53
Je n'est depuis plusieurs heures aucunes explications.
Merci d'avance, car là je suis bloqué.
Je suis bloqué depuis plusieurs heures sur un problème, j’essaye de convertir un tchat que j'avais fais en POO, il y a la page principale:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Tchat</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/../StockHG/Style.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<form method="post" action="programme.php" class="col-lg-4">
<lengend>Votre pseudo:</lengend><br/>
<input type="text" name="pseudo" class="form-control"/><br/>
<lengend>Votre pseudo:</lengend><br/>
<input type="text" name="message" class="form-control"/><br/>
<input type="submit" class="form-control"/>
</form>
<?php
require "tchat.class.php";
$db = new PDO("mysql:host=localhost;dbname=test;charset=utf8", "root", "");
$affichage = new Affichage();
$affichage->afficher();
?>
</body>
</html>
Une page qui traite les données:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Chargement...</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/../StockHG/Style.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<?php
require "tchat.class.php";
if(isset($_POST["pseudo"]) && isset($_POST["message"]))
{
$message = new Message($_POST["pseudo"], $_POST["message"]);
$message->insert();
}
?>
</body>
</html>
Une page où il y a les classes:
<?php
class Message
{
private $_db;
private $pseudo;
private $message;
private $autoEnreg;
public function __construct($pseudo, $message)
{
if(is_string($pseudo) && is_string($message))
{
$this->_pseudo = htmlspecialchars($pseudo);
$this->_message = htmlspecialchars($message);
$this->_db = new PDO("mysql:host=localhost;dbname=test;charset=utf8", "root", "");
$this->autoEnreg = true;
}
else
{
$this->_autoEnreg = false;
}
}
public function insert()
{
if($this->_autoEnreg == true)
{
$insert = $this->_db->prepare("INSERT INTO tchat SET pseudo = :pseudo, message = :message, dateEnregistrement = NOW()");
$insert->bindValue(":pseudo", $this->_pseudo);
$insert->bindValue(":message", $this->_message);
$insert->execute();
}
}
}
class Affichage
{
private $_db;
public function __construct()
{
$_db = new PDO("mysql:host=localhost;dbname=test;charset=utf8", "root", "");
}
public function afficher()
{
$affichage = $this->_db->query("SELECT * FROM tchat");
echo "ro";
while($liste = $affichage->fetch())
{
?>
<p>A: <?php $liste["dateEnregistrement"]; ?>, <?php $liste["pseudo"]; ?> a écrit: <?php $liste["message"]; ?></p>
<?php
}
}
}
?>
Et là on m'affiche:
Call to a member function query() on a non-object in C:\wamp\www\Entrainement\tchat.class.php on line 53
Je n'est depuis plusieurs heures aucunes explications.
Merci d'avance, car là je suis bloqué.
A voir également:
- Call to a member function query() on a non-object...
- Call to a member function query() on a non-object ✓ - Forum - PHP
- Call to a member function query() on a non-object... ✓ - Forum - PHP
- Fatal error: call to a member function query() on a non-object ✓ - Forum - PHP
- Call to a member function query() on string - Forum - PHP
- Fatal error: Uncaught Error: Call to a member function query() ✓ - Forum - PHP