Hey guys just asking for some help on my code to see where am going wrong thats all
Right am making a simple CMS site and my problem is that i want everything to be shown on my index page nothing is and i dont know why it is, my code should be right and nothing wrong with it
and its really annoying me now soo hope theres someone who can share-light on my mistake
this is my index.php
<?php
include '_class/cms_class.php';
$obj = new modernCMS();
$obj-> host = 'localhost';
$obj-> username = 'ronny';
$obj-> password = 'password';
$obj-> database = 'cms';
$obj-> connect();
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>My Modern CMS</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="page_wrap">
<?php
if(isset($_GET['id'])):
$obj->get_content($_GET['id']);
else:
$obj->get_content();
endif;
?>
</div>
</body>
</html>
and this is my cms_class.php
<?php
//---------------------------------------------------------------------------------------
class modernCMS {
var $host;
var $username;
var $password;
var $database;
// connection info
function connect(){
$connection = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error());
mysql_select_db($this->database, $connection) or die(mysql_error());
}
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
// to get the content from my database
function get_content($id = " "){
if ($id != ""):
$id = mysql_real_escape_string($id);
$sql = "SELECT * FROM posts WHERE id = '$id'";
$return = '<p><a href="index.php"> Go Back To Content Page</a></p>';
else:
$sql = "SELECT * FROM posts ORDER BY id DESC";
endif;
$res = mysql_query($sql) or die(mysql_error());
// if uses try to go on a id that doesnt exist message
if(mysql_num_rows($res) !=0):
while($row = mysql_fetch_assoc($res)){
echo '<h1><a href="index.php?id=' . $row['id']. '">' . $row['title'] . '</a></h1>';
echo '<p>' . $row['body'] . '</p>';
}
else:
echo '<p> UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST </p>'; //message to be displayed
endif;
echo $return;
}
}
?>
so basically when i click on the GO Back To Content Page
it just shows UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST
i know that but im sure iv programmed it right soo i can see all my posts on the index page
my own solution is that i can change the $return
from this:
$return = '<p><a href="index.php"> Go Back To Content Page</a></p>';
to this:
$return = '<p><a href="index.php?id="> Go Back To Content Page</a></p>';
and it will solve the problem
but i really shouldnt have to it should display when someone just goes on the "index.php" page, and not what av just suggested to solve the problem the "index.php?id=" page
can someone help please
kind regards