tutti i consigli su questa classe?

Stato
Discussione chiusa ad ulteriori risposte.
Fatal error: Call to a member function query() on a non-object in /membri/vincy6web/guest/PHPClass.php on line 79
questo e l'errore causato se metto il fatto del costruttore che connette e il distruttore che disconnette....
nn so perche...
Codice:
$db=new db("localhost","  "," "," ");
 $guestbook=new guestbook($db);

altra pagina
Codice:
    public function __construct($db){
        $db->connect();
    }
    public function __destruct(){
        $db->disconnect();
    }
public function read(){
        $db->query("SELECT * FROM guestbook ORDER BY id DESC");

        while($db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
in poche parole non riersce a chiamare i metodi della classe db...
 
ah grazie....

mi da lo stesso errore (a connettersi si connette pero e come se non mi facesse accedere al metodo query)
, ora i codici sono:
la index:
Codice:
$db=new db("localhost","my_ "," "," ");
$guestbook=new guestbook(&$db);
le classi:
Codice:
    public function __construct($db){
        $db->connect();
    }
    public function __destruct(){
        $db->disconnect();
    }
    public function control($nome,$testo,$data,$ora){
        $nome=trim($nome);
        $testo=trim($testo);
        if(empty($nome) || empty($testo)){
            throw new Exception(".:!Compilare tutti i campi, grazie!:.");
            return false;
        }else{
            $nome=htmlentities($nome);
            $testo=htmlentities($testo);
            $this->nome=$nome;
            $this->testo=$testo;
            $this->ora=$ora;
            $this->data=$data;
            return true;
        }
    }
    public function read(){
        $db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
se puoi potresti dirmi il perche? ...:)
grazoe
 
vincy6 ha detto:
ah grazie....

mi da lo stesso errore (a connettersi si connette pero e come se non mi facesse accedere al metodo query)
, ora i codici sono:
la index:
Codice:
$db=new db("localhost","my_ "," "," ");
$guestbook=new guestbook(&$db);
le classi:
Codice:
    public function __construct($db){
        $db->connect();
    }
    public function __destruct(){
        $db->disconnect();
    }
    public function control($nome,$testo,$data,$ora){
        $nome=trim($nome);
        $testo=trim($testo);
        if(empty($nome) || empty($testo)){
            throw new Exception(".:!Compilare tutti i campi, grazie!:.");
            return false;
        }else{
            $nome=htmlentities($nome);
            $testo=htmlentities($testo);
            $this->nome=$nome;
            $this->testo=$testo;
            $this->ora=$ora;
            $this->data=$data;
            return true;
        }
    }
    public function read(){
        $db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
se puoi potresti dirmi il perche? ...:)
grazoe



Hai ragione io ho scritto male perchè l'ho fatta direttamente sul forum giusto per farti l'esempio, però pure te arrivaci... lo scope di $db è relativo solo al costruttore, di conseguenza nelle altre funzioni non esiste. In ogni modo basta mettere $db come membro della classe inizializzarlo con il parametro e usare quello.

PHP:
private $db;
  public function __construct($db){
        $this->db = $db;
        $this->db->connect();
    }
//ecc ecc

usa il tag ['php] non ['code] per scrivere i sorgenti (senza ' ovviamente).
 
A questo c'ero arrivato.....
Forse non l'ho scritto.... scusa se ti ho fatto perdere tempo...
Solo che non sono riuscito a creare i metodi per le query e del fetch...
ti scrivo quelle che ho fatto io...
(e che non funzionano)
Codice:
public function query($query){
$query=mysql_query($query);
return $query;
}
l'altra la posto dopo...
se piuoi dirmi il perche o scrivermele tu saresti gentilissimo
 
I metodi potrebbero essere pure giusti, ma sicuramente li usi male
PHP:
    public function read(){
        $db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
questo è errato, dovrebbe essere
PHP:
  public function read(){
        $r = $db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($row = $db->fetch($r))
            array_push($this->read,$row);
   
    }
le funzioni query e fetch le ho già scritte da qualche parte.
 
ok
Pagina PHPclass.php
PHP:
<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Guestbook OOPhp
 *
 * @author Vincy6
 */
class db{
    private $host;
    private $name;
    private $user;
    private $pass;
    private $connect;
    public function __construct($host,$name,$user,$pass){
        $this->host=$host;
        $this->name=$name;
        $this->user=$user;
        $this->pass=$pass;
    }
    public function connect(){
        $this->connect=mysql_connect($this->host,$this->user,$this->pass);
        if(!$this->connect){
            throw new Exception(".:!Errore durante la connessione al database, se l'errore persiste contattare l'admin!:.");
        }else{
            $select=mysql_select_db("my_vincy6web",$this->connect);
            if(!$select){
               exit(".:!Errore durante la selezione!:.");
            }
        }
    }
    public function disconnect(){
        mysql_close($this->connect);
    }
    public function query($sql) {
      $query = mysql_query($sql);
       if(!$query)
          throw new Exception("Query non eseguita!");
      return $query;
}
    public function fetch($query) {
              return mysql_fetch_array($query);
    }
}

class guestbook{
    private $nome;
    private $testo;
    private $data;
    private $ora;
    public  $db;
    public  $read=array();
    public function __construct($db){
        $this->db=$db;
        $db->connect();
    }
    public function __destruct(){
        $this->db->disconnect();
    }
    public function control($nome,$testo,$data,$ora){
        $nome=trim($nome);
        $testo=trim($testo);
        if(empty($nome) || empty($testo)){
            throw new Exception(".:!Compilare tutti i campi, grazie!:.");
            return false;
        }else{
            $nome=htmlentities($nome);
            $testo=htmlentities($testo);
            $this->nome=$nome;
            $this->testo=$testo;
            $this->ora=$ora;
            $this->data=$data;
            return true;
        }
    }
    public function read(){
        $query=$this->db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($all=$this->db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
    public function write($nome,$testo,$data,$ora){
        if($this->control($nome,$testo,$data,$ora)){
            $query=mysql_query("INSERT INTO guestbook (nome,testo,data,ora) VALUE ('$nome','$testo','$data','$ora')");
            if(!$query){
                throw new Exception(".:!Commento non inserito correttamente, riprovare se l'errore persiste contattatare l'admin!:.");
            }else{
                throw new Exception(".:!Commento inserito correttamente!:.");
            }
        }
    }
}
?>
pagina index.php
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="style.css" />
        <title> | Gusetbook | </title>
    </head>
    <body>
        <div id="page">
            <div id="form">
                <form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
                    Nick :<br />
                    <input type="text" name="nome" class="input" />
                    <br />
                    Testo:<br />
                    <textarea name="testo" class="input" ></textarea>
                    <br /><br />
                    <input type="submit" value="invia" name="invia" class="input" />
                </form>
            </div>
        <?php
        include_once("PHPClass.php");
        try{
            $db=new db("localhost","my_ "," "," ");
            $guestbook=new guestbook(&$db);
            if(isset($_POST['invia'])){
                $nome=$_POST['nome'];
                $testo=$_POST['testo'];
                $data=date (" d-m-Y ");
                $ora=date(" H:i ");
                $guestbook->write($nome, $testo, $data, $ora);
            }
            $guestbook->read();
            $i=0;
            while($guestbook->read[$i]){
                echo
                '
                <div class="commenti">
                    <table border="1" class="table">
                        <tr>
                            <td class="nick">'.$guestbook->read[$i]["nome"].'</td>
                        </tr>
                        <tr>
                            <td class="testo"><p>'.$guestbook->read[$i]["testo"].'</p></td>
                        </tr>
                        <tr>
                            <td class="data">Questo commento e stato scritto da : '.$guestbook->read[$i]["nome"].' alle ore : '.$guestbook->read[$i]["ora"].' il giorno : '.$guestbook->read[$i]["data"].'</td>
                        </tr>
                    </table>
               </div>
               ';
                $i++;
            }
        }catch(Exception $e) {
            echo $e->getMessage();
        }
        ?>
        </div>
    </body>
</html>
 
Vabè, tutto sommato è accetabile, anche se non capisco perchè hai messo l'attributo $db publico e hai fatto il read in quel modo, si poteva fare diversamente.
 
Il db l'ho messo pubblico perche ho sbagliato e lo correggom il read in che altro modo si poteva fare?

(nn ho ancora corretto il exit(bla);)
xD
mi dimentico sempre...

(nn ho ancora corretto il exit(bla);)
xD
mi dimentico sempre...
 
Invece di scrivere così
PHP:
    public function read(){
        $query=$this->db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($all=$this->db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
basterebbe scrivere così
PHP:
    public function read(){
        $read = array();
        $query=$this->db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($all=$this->db->fetch($query))
            $read[] = $all;
        
        return $read; 
    }
poi, ovviamente, devi modificare la lettura cambiando
PHP:
 $guestbook->read();
            $i=0;
            while($guestbook->read[$i]){
                echo
                '
                <div class="commenti">
                    <table border="1" class="table">
                        <tr>
                            <td class="nick">'.$guestbook->read[$i]["nome"].'</td>
                        </tr>
                        <tr>
                            <td class="testo"><p>'.$guestbook->read[$i]["testo"].'</p></td>
                        </tr>
                        <tr>
                            <td class="data">Questo commento e stato scritto da : '.$guestbook->read[$i]["nome"].' alle ore : '.$guestbook->read[$i]["ora"].' il giorno : '.$guestbook->read[$i]["data"].'</td>
                        </tr>
                    </table>
               </div>
               ';
                $i++;
            }
con
PHP:
$data = $guestbook->read();
            foreach($data as $key=>$value) {
                echo
                '
                <div class="commenti">
                    <table border="1" class="table">
                        <tr>
                            <td class="nick">'.$value["nome"].'</td>
                        </tr>
                        <tr>
                            <td class="testo"><p>'.$value["testo"].'</p></td>
                        </tr>
                        <tr>
                            <td class="data">Questo commento e stato scritto da : '.$value["nome"].' alle ore : '.$value["ora"].' il giorno : '.$value["data"].'</td>
                        </tr>
                    </table>
               </div>
               ';
            }

E' una questione di gusti, ma, secondo me, è meglio così.
 
ciao ragazzi stavo facendo il capctah per questo guestbook ma e sorto un problema che mi sta incasinando e mi sono attaccato uil cervello
se volete potete aiutarmi ?
il problema e che ...
vedete voi:
PHP:
<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Guestbook OOPhp
 *
 * @author Vincy6
 */
class db{
    private $host;
    private $name;
    private $user;
    private $pass;
    private $connect;
    public function __construct($host,$name,$user,$pass){
        $this->host=$host;
        $this->name=$name;
        $this->user=$user;
        $this->pass=$pass;
    }
    public function connect(){
        $this->connect=mysql_connect($this->host,$this->user,$this->pass);
        if(!$this->connect){
            throw new Exception(".:!Errore durante la connessione al database, se l'errore persiste contattare l'admin!:.");
        }else{
            $select=mysql_select_db("my_vincy6web",$this->connect);
            if(!$select){
               exit(".:!Errore durante la selezione!:.");
            }
        }
    }
    public function disconnect(){
        mysql_close($this->connect);
    }
    public function query($sql) {
      $query = mysql_query($sql);
       if(!$query)
          throw new Exception("Query non eseguita!");
      return $query;
}
    public function fetch($query) {
              return mysql_fetch_array($query);
    }
}

class captcha{
    private $background;
    private $colortext;
    #private $colorline;
    public $text;
    private $world=array("a","b","c","d","f","g","h","i","l","m","n","o","p","q","r","s","t","u","v","z","k","y","j","1","2","3","4","5","6","7","8","9");
    private $img;
    public $ctext;
    public function __construct($img,$background,$colortext){
        $this->img=imageCreatetruecolor($img[0],$img[1]);
        $this->background=imageColorAllocate($this->img,$background[0],$background[1],$background[2]);
        $this->colortext=$colortext;
    }
    public function __destruct(){
        imageDestroy($img);
    }
    public function text(){
        $text=array();
        for($i=0;$i<8;$i++){
            $u=rand(0,32);
            array_push($text,$this->world[$u]);
        }
        $this->text=$text[0];
        for($i=1;$i<8;$i++){
            $this->text=$this->text." ".$text[$i];
        }
        $this->ctext=$text[0];
        for($i=1;$i<8;$i++){
            $this->ctext=$this->ctext."".$text[$i];
        }
    }
    public function write(){
        $this->colortext=imageColorAllocate($this->img,$this->colortext[0],$this->colortext[1],$this->colortext[2]);
        $texto=imageString($this->img,20,75,17,$this->text,$this->colortext);
        imagefill($this->img,0,0,$this->background);
        imagepng($this->img,"immagine.png");
        echo "<img src=\"immagine.png\">";
    }
    public function control($cap,$capt){
        if(strcmp($cap,$capt)==0){
            return true;
        }else{
            throw new Exception("Inserire correttamente il testo soprastante,grazie.");
            return false;
        }
    }

}

class guestbook{
    private $nome;
    private $testo;
    private $data;
    private $ora;
    public  $db;
    public  $read=array();
    public function __construct($db){
        $this->db=$db;
        $db->connect();
    }
    public function __destruct(){
        $this->db->disconnect();
    }
    public function control($nome,$testo,$data,$ora){
        $nome=trim($nome);
        $testo=trim($testo);
        if(empty($nome) || empty($testo)){
            throw new Exception(".:!Compilare tutti i campi, grazie!:.");
            return false;
        }else{
            $nome=htmlentities($nome);
            $testo=htmlentities($testo);
            $this->nome=$nome;
            $this->testo=$testo;
            $this->ora=$ora;
            $this->data=$data;
            return true;
        }
    }
    public function read(){
        $query=$this->db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($all=$this->db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
    public function write($nome,$testo,$data,$ora){
        if($this->control($nome,$testo,$data,$ora)){
            $query=mysql_query("INSERT INTO guestbook (nome,testo,data,ora) VALUE ('$nome','$testo','$data','$ora')");
            if(!$query){
                throw new Exception(".:!Commento non inserito correttamente, riprovare se l'errore persiste contattatare l'admin!:.");
            }else{
                throw new Exception(".:!Commento inserito correttamente!:.");
            }
        }
    }
}
?>
index
PHP:
<?php
include_once("PHPClass.php");
$captcha=new captcha($img=array("300","50"), $background=array("00","80","80"), $colortext=array("250","250","250"));
$db=new db("localhost","my_vincy6web","vincy6web","vincy6web");
$guestbook=new guestbook(&$db);
$captcha->text();
 ?>
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="style.css" />
        <title> | Gusetbook | </title>
    </head>
    <body>
        <div id="page">
            <div id="form">
                <form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
                    <p>Nick</p>
                    <input type="text" name="nome" class="input" />
                    <p>Testo:</p>
                    <textarea name="testo" class="input" ></textarea>
                    <p>Inserisci il testo dell'immagine:<p>
                    <p><?php $captcha->write();?></p>
                    <br />
                    <input type="hidden" value="<?php print $captcha->ctext;?>" name="capt" />
                    <input type="input" value="" name="cap" class="input" />
                    <br /><br />
                    <input type="submit" value="invia" name="invia" class="input" />
                </form>
            </div>
            <?php
            try{

                if(isset($_POST['invia'])){
                    $nome=$_POST['nome'];
                    $testo=$_POST['testo'];
                    $data=date (" d-m-Y ");
                    $ora=date(" H:i ");
                    $cap=$_POST['cap'];
                    $capt=$_POST['capt'];
                    if($captcha->control($cap,$capt)){
                         $guestbook->write($nome, $testo, $data, $ora);
                    }
                }
            $guestbook->read();
            $i=0;
            while($guestbook->read[$i]){
                echo
                '
                <div class="commenti">
                    <table border="1" class="table">
                        <tr>
                            <td class="nick">'.$guestbook->read[$i]["nome"].'</td>
                        </tr>
                        <tr>
                            <td class="testo"><p>'.$guestbook->read[$i]["testo"].'</p></td>
                        </tr>
                        <tr>
                            <td class="data">Questo commento e stato scritto da : '.$guestbook->read[$i]["nome"].' alle ore : '.$guestbook->read[$i]["ora"].' il giorno : '.$guestbook->read[$i]["data"].'</td>
                        </tr>
                    </table>
               </div>
               ';
                $i++;
            }

        }catch(Exception $e) {
            echo $e->getMessage();
        }
        ?>
        </div>
    </body>
</html>
e un casino...
quello che so...
1) devo aggiustare la classe(ma nn so come datemi qualche dritta)
2) maggior parte del code e sbagliato(aiutatemi)
xD
 
ia letti ed ho un problema che non so da quale parte del coice dervia forse perche confuso troppo e non riesco a ripararlo
visto che con le classi sono un principiante volevo essere consigliato non essere fatto il code...
dare qualche dritta= consigli...
:)
 
ok
...
allora in poche parole il capcta funzia solo che se sbagli ad inserirlo(il capt) ti da l'errore solo che poi il testo nell'immagine non cabia, ma nella var di controllo si quindi da sempre errore...

index
PHP:
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="style.css" />
        <title> | Gusetbook | </title>
    </head>
    <body>
        <div id="page">
            <?php
                try{
                session_start();
                include_once("PHPClass.php");
                $captcha=new captcha($img=array("300","50"), $background=array("00","80","80"), $colortext=array("250","250","250"));
                $db=new db("localhost","my_vincy6web","vincy6web","vincy6web");
                $guestbook=new guestbook(&$db);
                    if(isset($_POST['invia'])){
                    $nome=$_POST['nome'];
                    $testo=$_POST['testo'];
                    $data=date (" d-m-Y ");
                    $ora=date(" H:i ");
                    $s_c_i=$_POST['cap'];
                    if($captcha->control($s_c_i,$_SESSION['s_c'])){
                        $guestbook->write($nome, $testo, $data, $ora);
                    }
                 }
            ?>
            <div id="form">
                <form action="index.php" method="post">
                    <p>Nick</p>
                    <input type="text" name="nome" class="input" />
                    <p>Testo:</p>
                    <textarea name="testo" class="input" ></textarea>
                    <p>Inserisci il testo dell'immagine:<p>
                    <p><?php $captcha->text();$captcha->write();?></p>
                    <br />
                    <input type="input" value="" name="cap" class="input" />
                    <br /><br />
                    <input type="submit" value="invia" name="invia" class="input" />
                </form>
            </div>
            <?php
            $guestbook->read();
            $i=0;
            while($guestbook->read[$i]){
                echo
                '
                <div class="commenti">
                    <table border="1" class="table">
                        <tr>
                            <td class="nick">'.$guestbook->read[$i]["nome"].'</td>
                        </tr>
                        <tr>
                            <td class="testo"><p>'.$guestbook->read[$i]["testo"].'</p></td>
                        </tr>
                        <tr>
                            <td class="data">Questo commento e stato scritto da : '.$guestbook->read[$i]["nome"].' alle ore : '.$guestbook->read[$i]["ora"].' il giorno : '.$guestbook->read[$i]["data"].'</td>
                        </tr>
                    </table>
               </div>
               ';
                $i++;
            }

        }catch(Exception $e) {
            echo $e->getMessage();
        }
        ?>
        </div>
    </body>
</html>
classi
PHP:
<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Guestbook OOPhp
 *
 * @author Vincy6
 */
class db{
    private $host;
    private $name;
    private $user;
    private $pass;
    private $connect;
    public function __construct($host,$name,$user,$pass){
        $this->host=$host;
        $this->name=$name;
        $this->user=$user;
        $this->pass=$pass;
    }
    public function connect(){
        $this->connect=mysql_connect($this->host,$this->user,$this->pass);
        if(!$this->connect){
            throw new Exception(".:!Errore durante la connessione al database, se l'errore persiste contattare l'admin!:.");
        }else{
            $select=mysql_select_db("my_vincy6web",$this->connect);
            if(!$select){
               exit(".:!Errore durante la selezione!:.");
            }
        }
    }
    public function disconnect(){
        mysql_close($this->connect);
    }
    public function query($sql) {
      $query = mysql_query($sql);
       if(!$query)
          throw new Exception("Query non eseguita!");
      return $query;
}
    public function fetch($query) {
              return mysql_fetch_array($query);
    }
}

class captcha{
    private $colortext;
    private $background;
    private $img;
    private $world;
    public $text;
    public $ctext;
    public function __construct($img,$background,$colortext){
        $this->img=imageCreatetruecolor($img[0],$img[1]);
        $this->background=imageColorAllocate($this->img,$background[0],$background[1],$background[2]);
        $this->colortext=$colortext;
        $this->world=md5(microtime());
    }
    public function __destruct(){
        imageDestroy($img);
        $this->world="";
    }
    public function text(){
        $_SESSION['s_c']=substr($this->world, 0, 5);
        $this->text=$_SESSION['s_c'][0];
        for($i=1;$i<8;$i++){
            $this->text=$this->text." ".$_SESSION['s_c'][$i];
        }
    }
    public function write(){
        $this->colortext=imageColorAllocate($this->img,$this->colortext[0],$this->colortext[1],$this->colortext[2]);
        $texto=imageString($this->img,20,75,17,$this->text,$this->colortext);
        imagefill($this->img,0,0,$this->background);
        imagepng($this->img,"immagine.png");
        echo "<img src=\"immagine.png\">";
    }
    public function control($cap,$capt){
        if(strcmp($cap,$capt)==0){
            return true;
        }else{
            print ("Inserire correttamente il testo soprastante,grazie.");
            return false;
        }
    }

}

class guestbook{
    private $nome;
    private $testo;
    private $data;
    private $ora;
    public  $db;
    public  $read=array();
    public function __construct($db){
        $this->db=$db;
        $db->connect();
    }
    public function __destruct(){
        $this->db->disconnect();
    }
    public function control($nome,$testo,$data,$ora){
        $nome=trim($nome);
        $testo=trim($testo);
        if(empty($nome) || empty($testo)){
            print (".:!Compilare tutti i campi, grazie!:.");
            return false;
        }else{
            $nome=htmlentities($nome);
            $testo=htmlentities($testo);
            $this->nome=$nome;
            $this->testo=$testo;
            $this->ora=$ora;
            $this->data=$data;
            return true;
        }
    }
    public function read(){
        $query=$this->db->query("SELECT * FROM guestbook ORDER BY id DESC");
        while($all=$this->db->fetch($query)){
            $this->nome=$all['nome'];
            $this->testo=$all['testo'];
            $this->data=$all['data'];
            $this->ora=$all['ora'];
            array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
        }
    }
    public function write($nome,$testo,$data,$ora){
        if($this->control($nome,$testo,$data,$ora)){
            $query=mysql_query("INSERT INTO guestbook (nome,testo,data,ora) VALUE ('$nome','$testo','$data','$ora')");
            if(!$query){
                throw new Exception(".:!Commento non inserito correttamente, riprovare se l'errore persiste contattatare l'admin!:.");
            }else{
                throw new Exception(".:!Commento inserito correttamente!:.");
            }
        }
    }
}
?>


ho inserito alcune print per un problema che ho cambiato topic...
 
Eh.. perchè la parola la generi dentro il costruttore, dovresti mettere
PHP:
$this->world=md5(microtime());
nella funzione in cui generi l'immagine! Se la funzione text della classe la invochi sempre insieme a write, metti la chiamata all'interno di write, rendi privata text e chiami solo write all'esterno. La generazione della parola la fai all'interno di write.

[ot]world != word[/ot]
 
ok provo...
gentilissimo ocme sempre...
e che dici la struttura e uno schifo vero?

mo sai che faccio?
riscrivo la classe....
 
domanda: ma dove stai studiando l'oop? pian piano hai raggiunto almeno la decenza, grazie a questo topic, certo, ma studiare su una guida a mio parere è meglio di imparare facendo pratica
 
Anche perché stoner è stato un santo, difficilmente trovi qualcuno che ti segue così bene, più facilmente ti viene detto di rileggerti bene la teoria prima di cimentarti nella pratica, anche perché è il metodo migliore, così non sei andato così avanti a mio parere. Hai solo fatto una classe funzionante.
 
ragazzi, ho finito il captcha....
fiu finalmente...:sleepy:
se volete vederlo:
http://vincy6web.altervista.org/cap/
Grazie di tutto....
appena sistemo il codice lo posto cosi mi date consigli....(se volete,come sempre d'altronde)
 
Codice:
Pagina index mancante

La cartella /cap/ non contiene una pagina index.

Devi creare una pagina che si chiami index.html, index.htm oppure index.php (tutto minuscolo).

http://www.altervista.org

difficile che lo vediamo :asd:
 
ah si ragazzi scusate ho spostato il tutto... perche ora ho messo la cartella guestbook e il capctha in cartelle separate in modo da poter usare il captcha anche in altre situazioni snza pasticci...
ecco a voi:
http://vincy6web.altervista.org/guestbook/
 
Stato
Discussione chiusa ad ulteriori risposte.