sorry for my English.

My knowledge about the database is very simple.

I have to come this code from a Forum.

My problem, when anyone writes a comment, it shows on all Website, when I to wish that it only to display on the File where it writes.

I to try to solve this problem with....

I have Two Files, one with the Php code, code.php then another where the comment is display, comment.php.

On comment.php file have top above,

include '/var/www/html/code.php';

and bellow where the comment display

<?php $object = new ClassProveContakt3("1");?> 

On code.php top above, declare the properties to $site,

 private $site;

The function __construct($site) mit de parameter $site, I to call it with,

public function __construct($site) {


When updating the comment.php page, to come Two warning,


Trying to get property '1' of non-object in /var/www/html/code.php on line 35

On line 35 have $this->site->$site;


Undefined variable: site in /var/www/html/code.php on line 164

On line 164 have $sth -> execute( array(':site' => $site ));,

it is the function to conect to database, this function,

function getMessages()
    if ( ! $this -> dbh ) {
        $this -> getConnection();

    $sql = "SELECT * FROM commentar WHERE site = :site ORDER BY datetime DESC";
    $sth = $this->dbh->prepare( $sql, array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY ));
    $sth -> execute( array(':site' => $site ));

    $result = $sth->fetchAll(PDO::FETCH_ASSOC );
    if ( false === $result ) {
        $this->reportPDOError( "fetchAll(ASSOC) failed", $sql );
    foreach ($result as $message) {


 <p><strong>From: </strong> <?=htmlspecialchars( $message['name'] ) ?>            
 <strong>at: </strong> <?=htmlspecialchars( $message['datetime'] ); ?></p>
 <p><?=htmlspecialchars( $message['message'] ); ?></p><hr>


All Code from code.php is here

Can please someone help me with this problem, Thanks!


I "found" the solution, people give me the solution but I too to search...

On comment.php

In comment.php file have top above,

include '/var/www/html/code.php';

remove it.

and bellow where the comment display, change from

<?php $object = new ClassProveContakt3("1");?> 


include_once '/var/www/html/code.php';

Because of used include_once and not include here to say why.

On code.php

In Line 163 change from

 $sth -> execute( array(':site' => $site ));


$sth -> execute( array(':site' => $_SERVER['REQUEST_URI'] ) );

Why $_SERVER['REQUEST_URI'] ? , as php to say about 'REQUEST_URI', The URI which was given in order to access this page. I want that comment only to display on the File where it writes. It to say , when site = place where I'm .....write here.

In Line 183 change from

$Newobject = new ClassProveContakt3();


$Newobject = new ClassProveContakt3($_SERVER['REQUEST_URI']);

Why $_SERVER['REQUEST_URI']?, when the comment.php file call the $Newobject object, it is the Parameter which send to comment.php

I thank all the people who help me with this problem!

Not the answer you're looking for? Browse other questions tagged or ask your own question.