<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
/* Open a connection */
$mysqli = new mysqli("localhost", "DATABASE_NAME", "DATABASE_PASSWORD", "DATABASE_USER");
/* check connection */
if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
/* process input */
foreach($_REQUEST as $key => $value){ $$key = $value;}
/* find homepage */
$homepageid=1;
/* process nav to determine type & typeid */
if(isset($id)){
$sql = "SELECT type, typeid FROM nav WHERE id = $id";
if ($result = $mysqli->query($sql)) {
$row = $result->fetch_assoc();
foreach($row as $key => $value) {
$$key = html_entity_decode($value, ENT_QUOTES);
}
$result->free();
}
}
/* process output */
$sql = "SELECT * FROM $type WHERE `id` = '$typeid'";
if ($result = $mysqli->query($sql)) {
$row = $result->fetch_assoc();
foreach($row as $key => $value) {
$newvarible =$type."_".$key;
$$newvarible = html_entity_decode($value, ENT_QUOTES);
}
$result->free();
}
echo "<h3>$page_title</h3>
$page_content";
/* process navigation */
$sql = "SELECT nav.id, nav.title FROM relations INNER JOIN nav ON relations.childtypeid=nav.id WHERE parenttype = 'menu' AND parenttypeid = '1'";
if ($result = $mysqli->query($sql)) {
echo "<ul>";
while ($row = $result->fetch_assoc()) {
echo "<li><a href='index.php?id={$row['id']}'>{$row['title']}</a></li>";
}
echo "</ul>";
}
<?php $mysqli->close(); ?>
<html>
<body>
<h1><u>CMS Example #2</u></h1>
<?php
/* Enable error reporting */
error_reporting(E_ALL);
ini_set('display_errors', 1);
/* Open a connection */
$mysqli = new mysqli("localhost", "DATABASE_NAME", "DATABASE_PASSWORD", "DATABASE_USER");
/* check connection */
if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
/* process input - create a variable for each input and assign the value*/
foreach($_REQUEST as $key => $value){ $$key = $value;}
/* process actions */
if(isset($action)){
echo "<p>PROCESSING ACTION...</p>";
if($action=="login"){
echo "<p>PROCESSING LOGIN...</p>";
unset($action);
echo "<p>LOGIN SUCCESS... REDIRECTING TO DASHBOARD</p>";
$display="dashboard";
}
}
/* find homepage */
$homepageid=1;
if(isset($display)){
if($display=="login") {
echo "<p>LOGIN VIEW<p>
<p>To login, please <a href='index.php?action=login'>click here</a>.";
}elseif($display=="dashboard") {
echo "<p>DASHBOARD VIEW</p>
<ul>
<li>To view all pages <a href='index.php?display=view&type=page'>click here</a>.</li>
<li>To add a new page <a href='index.php?display=add&type=page'>click here</a>.</li>
</ul>";
}elseif($display=="add") {
echo "<p>ADD VIEW</p>";
}elseif($display=="view") {
echo "<p>DISPLAY ALL VIEW</p>";
}
}elseif(isset($id)||(isset($type)&&isset($typeid))){
/* process nav to determine type & typeid */
if(isset($id)){
$sql = "SELECT type, typeid FROM nav WHERE id = $id";
if ($result = $mysqli->query($sql)) {
$row = $result->fetch_assoc();
foreach($row as $key => $value) {
$$key = html_entity_decode($value, ENT_QUOTES);
}
$result->free();
}
}
/* process output */
$sql = "SELECT * FROM $type WHERE `id` = '$typeid'";
if ($result = $mysqli->query($sql)) {
$row = $result->fetch_assoc();
foreach($row as $key => $value) {
$newvarible =$type."_".$key;
$$newvarible = html_entity_decode($value, ENT_QUOTES);
}
$result->free();
}
echo "<h3>$page_title</h3>
$page_content";
}else{
/* display home page */
echo "<p>HOME PAGE</p>";
}
?>
<h2>Menu</h2>
<?php
/* process navigation */
$sql = "SELECT nav.id, nav.title FROM relations INNER JOIN nav ON relations.childtypeid=nav.id WHERE parenttype = 'menu' AND parenttypeid = '1'";
if ($result = $mysqli->query($sql)) {
echo "<ul>";
while ($row = $result->fetch_assoc()) {
echo "<li><a href='index.php?id={$row['id']}'>{$row['title']}</a></li>";
}
echo "</ul>";
$result->free();
}
$mysqli->close();
?>
</body>
</html>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)