Imam problem sa sljedecim kodom:
<?php
class simpleCMS {
var $host;
var $username;
var $password;
var $table;
public function display_public() {
$q = "SELECT * FROM testDB ORDER BY created DESC LIMIT 5";
$r = mysql_query($q);
if ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_assoc($r) ) {
$title = stripslashes($a['title']);
$bodytext = stripslashes($a['bodytext']);
$entry_display .= <<<ENTRY_DISPLAY
<div class="post">
<h2>
$title
</h2>
<p>
$bodytext
</p>
</div>
ENTRY_DISPLAY;
}
} else {
$entry_display .= <<<ENTRY_DISPLAY
<h2> This Page Is Under Construction </h2>
<p>
No entries have been made on this page.
Please check back soon, or click the
link below to add an entry!
</p>
ENTRY_DISPLAY;
}
$entry_display .= <<<ADMIN_OPTION
<p class="admin_link">
<a href="{$_SERVER['PHP_SELF']}?admin=1">Nova vijest</a>
</p>
ADMIN_OPTION;
return $entry_display;
}
public function display_admin() {
return <<<ADMIN_FORM
<form action="{$_SERVER['PHP_SELF']}" method="post">
<label for="title">Naslov:</label><br />
<input name="title" id="title" type="text" maxlength="150" />
<div class="clear"></div>
<label for="bodytext">Tekst:</label><br />
<textarea name="bodytext" id="bodytext"></textarea>
<div class="clear"></div>
<input type="submit" value="Objavi!" />
</form>
<br />
<a href="index.php">Natrag</a>
ADMIN_FORM;
}
public function write($p) {
if ( $_POST['title'] )
$title = mysql_real_escape_string($_POST['title']);
if ( $_POST['bodytext'])
$bodytext = mysql_real_escape_string($_POST['bodytext']);
if ( $title && $bodytext ) {
$created = time();
$sql = "INSERT INTO testDB VALUES('$title','$bodytext','$created')";
return mysql_query($sql);
} else {
return false;
}
}
public function connect() {
mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
return $this->buildDB();
}
private function buildDB() {
$sql = <<<MySQL_QUERY
CREATE TABLE IF NOT EXISTS testDB (
title VARCHAR(150),
bodytext TEXT,
created VARCHAR(100)
)
MySQL_QUERY;
return mysql_query($sql);
}
}
?>
Na stranici mi pokazuje sljedece greske:
Notice: Undefined index: admin in C:\wamp\www\SimpleCMS\index.php on line 50
Notice: Undefined variable: entry_display in C:\wamp\www\SimpleCMS\_class\simpleCMS.php on line 31
Sve radi, sadrzaj se moze objaviti ali me zanima zasto pokazuje greske.
Kod sa stranice odakle se ucitava:
<?php
include_once('_class/simpleCMS.php');
$obj = new simpleCMS();
/* CHANGE THESE SETTINGS FOR YOUR OWN DATABASE */
$obj->host = 'localhost';
$obj->username = 'root';
$obj->password = '';
$obj->table = 'newsadd';
$obj->connect();
if ( $_POST )
$obj->write($_POST);
echo ( $_GET['admin'] == 1 ) ? $obj->display_admin() : $obj->display_public();
?>