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) {
$this->site->$site;
...
When updating the comment.php page, to come Two warning,
1)
Trying to get property '1' of non-object in /var/www/html/code.php on line 35
On line 35 have $this->site->$site;
2)
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>
<?php
}
}
}
All Code from code.php is here
Can please someone help me with this problem, Thanks!