Salve, premetto che sto studiando le classi davvero da pochi giorni. Questo è il file config dove sono segnate le classi del blog:
Codice PHP:
<?php
class blog{
private $db_host;
private $db_user;
private $db_pass;
private $db_name;
public $conn;
public $sel;
public function __construct(){
$this->db_host='localhost';
$this->db_user='root';
$this->db_pass='';
$this->db_name='login';
$this->conn=mysql_connect($this->db_host,$this->db_user,$this->db_pass);
$this->sel=mysql_select_db($this->db_name,$this->conn);
}
}class conn extends blog{
public function Errore_connessione(){
if(!$this->conn){
die('Errore di connessione');
}
}
public function Errore_selezione(){
if(!$this->sel){
die('Errore di connessione del database');
}
}
}class insert extends conn{
public $post;
public $utente;
public $testo;
public function InsertCommenti(){
if(isset($this->conn)){
$this->post=@$_SESSION['post'];
$this->utente=@$_SESSION['utente'];
$this->testo=@$_POST['testo'];
$query="INSERT INTO commenti (post, utente, testo) VALUES ('{$this->post}','{$this->utente}','{$this->testo}')";
$result=mysql_query($query, $this->conn) or die ("Errore nella query ".mysql_error());
}else{
die('Errore nella query');
}
}
}class select extends insert{
public $query;
public $result;
public function __construct(){
$this->query="SELECT*FROM commenti WHERE post='{$this->post}'";
$this->result=mysql_query($this->query, $this->conn) or die ("Errore: ".mysql_error());
}
public function SelectCommenti(){
if(isset($this->conn)){
$this->query;
$this->result;
}else{
die('Errore nella selezione '.mysql_error());
}
}
}
$conn = new blog();
$conn->conn;
$sel= new blog();
$sel->sel;
$Errore_connessione = new conn();
$Errore_connessione->Errore_connessione();
$Errore_selezione = new conn();
$Errore_selezione->Errore_selezione();
?>
La query di inserzione dei commenti funziona ed è la seguente:
Codice PHP:
<?php
$insert = new insert();
$insert->InsertCommenti();
include('commenti_pubblicati.php');
?>
Il problema è che non funziona la visualizzazione dei commenti, programmata nel file 'commenti_pubblicati.php', ch'è il seguente:
Codice PHP:
<?php
$select = new select();
$select->SelectCommenti();
$result = new select();
$result->result;
echo('
<table width=700px;>
');
while($assoc=mysql_fetch_assoc($result->result))
{
echo('
<tr><td>di '.$assoc['utente'].'</td><td>il '.$assoc['data'].'</td></tr>
<tr><td colspan="2">'.$assoc['testo'].'</td></tr>
');
}
echo('
</table>
');
?>
Mi dice "Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\blog\config.php on line 57
Errore: ".
Questa è la linea 57:
Codice PHP:
$this->result=mysql_query($this->query, $this->conn) or die ("Errore: ".mysql_error());
Mi spiegate come devo correggere, per favore?