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

Recommended Answers

All 5 Replies

In cms_class.php line 26 change it to this and see if it works.

$sql = "SELECT * FROM posts WHERE id = '".$id."'";

thanks for the reply

but it still doesnt show any of the posts on the index.php page just the same as before with the "UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST" GO Back To Content Page

even when you click on the GO Back To Content Page it stays the same ....

The only thing I can think is that these 2 lines don't match

function get_content($id = " "){

if ($id != ""):

You are saying if no id is sent through the id equals space but then you want id to be nothing in your if statement, try taking out the space in the function

function get_content($id = "")

OH MY GOD
you GREAT HUMAN BEING I THANK YOU

to be honest i thought spaces won't make any difference but then after you mentioned it i realised,

"hang on a minute it reads white spaces ahhhh am such a freaking noob
cant believe i didnt notice that"

THANK YOU SIMPLYPIXIE your a star and i like to thank SOGO7 as well for trying to help me too

cheers guys now i can carry on with this and finish it off

No problem - I remember what it is like to be a noob and also miss things that can seem obvious once pointed out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.