Jump to content

get_content()?> is displaying??


chrisdixon

Recommended Posts

hello, I am currently trying to make a simple CMS System for a class assignment due soon. i have just commenced and i made a cms_class.php file and it contains the following:

 

<?php

 

class modernCMS {

 

var $host;

var $username;

var $password;

var $db;

 

function connect() {

$con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error());

mysql_select_db($this->db, $con) or die(mysql_error());

 

}

 

function get_content(){

$sql = "SELECT * FROM cms_content";

$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){

echo '<h1>' . $row['title'] . '</h1>';

echo '<p>' . $row['body'] . '</p>';

}

}

 

}//Ends our class

 

?>

 

 

My index.php file contains the following:

 

<?php

include '_class/cms_class.php';

$obj = new modernCMS();

 

//Setup Our Connection Vars

$obj->host = 'localhost';

$obj->username = '';

$obj->password = '';

$obj->db = 'modernCMS';

 

//connect to our DB

 

$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">

<?=$obj->get_content()?>

 

 

</div>

</body>

</html>

 

when i go to look at this on my localhost it is only showing up "get_content()?>"

I am wanting it to display content from my "cms_content" table i just made and is present in phpmyadmin.

any input would be very much appreciated.

Thanks :)

 

Link to comment
https://forums.phpfreaks.com/topic/204014-get_content-is-displaying/
Share on other sites

There are three possible explanations for this:

 

  • PHP isn't enabled on the server you're using
  • Short tags are disabled on the server so use

<?php echo $obj->get_content() ?>

instead of

<?=$obj->get_content()?>


  • You've named your file xyz.html instead of xyz.php

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.