Jump to content

Undefined variable Error


heric9

Recommended Posts

Everything seems to be working like it should iam getting Undegined variable Error : return in /Applications/MAMP/htdocs/modernCMS/_class/cms_class.php on line 37.

 

 

cms_class.php file

<?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($id = '') {

	if($id != ""):
		$id = mysql_real_escape_string($id);
		$sql = "SELECT * FROM cms_content WHERE id = '$id'";	

		$return = '<p><a href="index.php">Go Back To Content</a></p>';
	else:
		$sql = "SELECT * FROM cms_content ORDER BY id DESC";
	endif;

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

	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 Oh!, this doesn\'t exist!</p>';
	endif;

	echo $return;

}


} //Class ends here


index.php
?>

 

<?php

include '_class/cms_class.php';

$obj = new modernCMS();

$obj->host =  'localhost';
$obj->username =  'root';
$obj->password =  'root';
$obj->db =  'modernCMS';

$obj->connect();

?>
<!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>Untitled Document</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8">

</head>

<body>

<div id="page-wrap">
<?php 

if(isset($_GET['id'])):
$obj->get_content($_GET['id']);
else:
$obj->get_content();
endif;



?>
</div>
</body>
</html>

 

if anyone could help would be great. thanks.

Link to comment
https://forums.phpfreaks.com/topic/250995-undefined-variable-error/
Share on other sites

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.