(la pregunta/problema al final)
NOTA: la parte de codigo que es el administrador esta obsoleto, se modifica mediante acceso directo a la base de datos mediante phpmyadmin
DISPLAY.PHP---------------------------
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple CMS with PHP</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<?php
include_once('_class/simpleCMS.php');
$obj = new simpleCMS();
/* CHANGE THESE SETTINGS FOR YOUR OWN DATABASE */
$obj->host = 'localhost';
$obj->username = 'USUARIO';
$obj->password = 'CNTRASEÑA';
$obj->table = 'TABLA';
$obj->connect();
if ( $_POST )
$obj->write($_POST);
echo ( $_GET['admin'] == 1 ) ? $obj->display_admin() : $obj->display_public();
?>
</div>
</body>
</html>
_CLASS/SIMPLECMS.PHP-------------------------------
Código PHP:
<?php
class simpleCMS {
var $host;
var $username;
var $password;
var $table;
public function display_public() {
$q = "SELECT * FROM testDB ORDER BY created DESC LIMIT 500";
$r = mysql_query($q);
if ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_assoc($r) ) {
$title = stripslashes($a['title']);
$valor1 = stripslashes($a['valor1']);
$entry_display .= <<<ENTRY_DISPLAY
<div class="post">
$valor1
</div>
ENTRY_DISPLAY;
}
} else {
$entry_display = <<<ENTRY_DISPLAY
<h2> Esta pagina esta en construccion</h2>
<p>
Ninguna entrada se ha hecho en esta pagina.
</p>
ENTRY_DISPLAY;
}
$entry_display .= <<<ADMIN_OPTION
<p class="admin_link">
<a href="{$_SERVER['PHP_SELF']}?admin=1">Añadir una entrada nueva</a>
</p>
ADMIN_OPTION;
return $entry_display;
}
public function display_admin() {
return <<<ADMIN_FORM
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p>
<b>
<input type="radio" name="RadioGroup1" value="1" id="ALCISTA" />
<label>++</label>
<br />
<input type="radio" name="RadioGroup1" value="2" id="_ALCISTA" />
<label>+</label>
<br />
<input type="radio" name="RadioGroup1" value="3" id="STANDART" />
<label>STANDART</label>
<br />
<input type="radio" name="RadioGroup1" value="4" id="SOPORTE" />
<label>-</label>
<br />
<input type="radio" name="RadioGroup1" value="5" id="ZONA" />
<label>--</label>
<br />
</b>
</p>
<div class="clear"></div>
<br />
<label for="title" class="labeles" >VALOR:</label>
<input name="title" id="title" type="text" maxlength="100" size="75" />
<div class="clear"></div>
<input type="submit" value=" Crear la entrada! " />
</form>
<br />
<a href="display.php">Ir a Inicio</a>
ADMIN_FORM;
}
public function write($p) {
if ( $_POST['RadioGroup1'] )
$valor1 = mysql_real_escape_string($_POST['RadioGroup1']);
if ( $_POST['title'])
$title = mysql_real_escape_string($_POST['title']);
if ( $title && $valor1) {
$sql = "INSERT INTO testDB VALUES('$title','$valor1')";
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) CHARACTER SET utf8 COLLATE utf8_spanish2_ci DEFAULT NULL,
`valor1` text CHARACTER SET utf8 COLLATE utf8_spanish2_ci,
`bodytext` text CHARACTER SET utf8 COLLATE utf8_spanish2_ci,
`created` varchar(100) CHARACTER SET utf8 COLLATE utf8_spanish2_ci DEFAULT NULL,
`day` text CHARACTER SET utf8 COLLATE utf8_spanish2_ci NOT NULL,
`by` text CHARACTER SET utf8 COLLATE utf8_spanish2_ci NOT NULL
)
MySQL_QUERY;
return mysql_query($sql);
}
}
?>
Código PHP:
<?php
$imgup ='<img src="img/up.png" width="50"/>';
$imgmas2 = '<img src="img/n+2.png" width="50"/>';
$imgmas1 = '<img src="img/n+1.png" width="50"/>';
$imgneutro = '<img src="img/n.png" width="50"/>';
$imgmen1 = '<img src="img/n-1.png" width="50"/>';
$imgmen2 = '<img src="img/n-2.png" width="50"/>';
$imgdown = '<img src="img/down.png" width="50"/>';
if ($valor1 == 1) { echo $imgup; }
elseif ($valor1 == 2) { echo $imgmas2; }
elseif ($valor1 == 3) { echo $imgneutro; }
elseif ($valor1 == 4) { echo $imgmen2; }
elseif ($valor1 == 5) { echo $imgdown; }
?>
Código PHP:
public function display_public() {
$q = "SELECT * FROM testDB ORDER BY created DESC LIMIT 500";
$r = mysql_query($q);
if ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_assoc($r) ) {
$title = stripslashes($a['title']);
$valor1 = stripslashes($a['valor1']);
$entry_display .= <<<ENTRY_DISPLAY
<div class="post">
$imgup ='<img src="img/up.png" width="50"/>';
$imgmas2 = '<img src="img/n+2.png" width="50"/>';
$imgmas1 = '<img src="img/n+1.png" width="50"/>';
$imgneutro = '<img src="img/n.png" width="50"/>';
$imgmen1 = '<img src="img/n-1.png" width="50"/>';
$imgmen2 = '<img src="img/n-2.png" width="50"/>';
$imgdown = '<img src="img/down.png" width="50"/>';
if ($valor1 == 1) { echo $imgup; }
elseif ($valor1 == 2) { echo $imgmas2; }
elseif ($valor1 == 3) { echo $imgneutro; }
elseif ($valor1 == 4) { echo $imgmen2; }
elseif ($valor1 == 5) { echo $imgdown; }
</div>
ENTRY_DISPLAY;
}
} else {
$entry_display = <<<ENTRY_DISPLAY
<h2> Esta pagina esta en construccion</h2>
<p>
Ninguna entrada se ha hecho en esta pagina.
</p>