Undefined property: error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rdo
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 9:36 pm

Undefined property: error

Post by rdo »

Please dont hate on me but I am a ASP programmer, totally new to PHP. I am agreed to take on maintaining a php site for a non-profit. They provided me with all of their files and have restored the DB's from their backup. Now the pages load but I am getting the following error:

Notice: Undefined property: committee::$committeeGoals in C:\wamp\www\includes\class.committee.php on line 48

Line 48 is:
if( trim($this->committeeGoals) != "" ) {

The entire function starting at line 41 is:
function display() {

echo '<h1>'.$this->committeeName.'</h1>'."\n";
echo $this->committeeDescription."\n";

echo "<hr />\n";

if( trim($this->committeeGoals) != "" ) {
echo $this->committeeGoals;
echo "<hr />\n";
}
echo $this->committeeCalendar."\n";
echo "<hr />";
echo "<h3>Committee Documents:</h3>\n";
echo $this->committeeMinutes."\n";
echo "<hr />";
echo "<h3>Committee Members</h3>";
echo $this->committeeMembers."\n";
echo "<br />\n";
}

Can anyone please tell me how I can go about fixing this error?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined property: error

Post by social_experiment »

It looks like the property ( committeeGoals ) is not set inside the class 'committee. Could you paste the class code?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
rdo
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 9:36 pm

Re: Undefined property: error

Post by rdo »

<?php

class committee {

function committee() {

include_once("includes/class.db.php");
$db = new database();
}

function setValues($name) {

$valid = $this->fetchCommittee($name);
$this->path = strtolower($name);
$this->path = str_replace(" ", "_", $this->path);
$this->path = str_replace("'", "", $this->path);

if( !$valid ) {
header("Location: http://www.**********.org");
}
$this->formatDescription();

//Goals
$this->fetchGoals();
$this->formatGoals();

//Events/RSVP
$this->fetchCalendar();
$this->formatCalendar();

//Minutes
$this->fetchMinutes();
$this->formatMinutes();

//Members
$this->fetchMembers();
$this->formatMembers();

}

function display() {

echo '<h1>'.$this->committeeName.'</h1>'."\n";
echo $this->committeeDescription."\n";

echo "<hr />\n";

if( trim($this->committeeGoals) != "" ) {
echo $this->committeeGoals;
echo "<hr />\n";
}
echo $this->committeeCalendar."\n";
echo "<hr />";
echo "<h3>Committee Documents:</h3>\n";
echo $this->committeeMinutes."\n";
echo "<hr />";
echo "<h3>Committee Members</h3>";
echo $this->committeeMembers."\n";
echo "<br />\n";
}

function fetchCommittee($name) {

$sql = "SELECT * FROM `committee` WHERE LOWER(name) = LOWER('".$name."') LIMIT 1";
$results = mysql_query($sql) or die(mysql_error());

if( mysql_num_rows($results) != 1 ) {
return false;
}

$row = mysql_fetch_assoc($results);

$this->committeeName = $row['name'];
$this->committeeId = $row['Key_ID'];
$this->committeeDescription = $row['description'];
$this->committeeGoalHeader = $row['goal_header'];
return true;
}// end fetchCommittee

function formatDescription() {

$temp = $this->committeeDescription;
$content = explode("\n", $temp);

foreach($content as $value) {
if( trim($value) != "" ) {
$value = str_replace("\n", "", $value);
$value = str_replace("\r", "", $value);
$value = str_replace(" ", "\"", $value);
$value = str_replace(" ", "\"", $value);
$value = str_replace(" ", "'", $value);
$value = str_replace(" ", " - ", $value);
$value = str_replace("&", "&", $value);
$value = str_replace(" ", "...", $value);
$value = "<p>".$value."</p>\n";
}
}
if( $value == "" ) {
$value = "<p>Coming Soon!</p>";
}
$this->committeeDescription = $value;
}// end formatDescription

function fetchMinutes() {

$sql = "SELECT * FROM `minutes` WHERE committee_id = ".$this->committeeId." ORDER BY `dateAdded` DESC";
$results = mysql_query($sql);

if( mysql_num_rows($results) == 0 ) {
$this->minutes = "There are currently no documents available for this committee";
return false;
}

while($row = mysql_fetch_assoc($results) ) {
$this->minutes[] = $row;
}
}// end fetchMinutes

function formatMinutes() {

if( !is_array($this->minutes) ) {
$this->committeeMinutes = ''.$this->minutes.'';
return false;
}

$this->committeeMinutes = '<ul class="minuteList">'."\n";

for( $i = 0; $i < sizeof($this->minutes); $i++ ) {

$this->minutes[$i]['description'] = str_replace("\n", "", $this->minutes[$i]['description']);
$this->minutes[$i]['description'] = str_replace("\r", "", $this->minutes[$i]['description']);
$this->minutes[$i]['description'] = str_replace(" ", "\"", $this->minutes[$i]['description']);
$this->minutes[$i]['description'] = str_replace(" ", "\"", $this->minutes[$i]['description']);
$this->minutes[$i]['description'] = str_replace(" ", "'", $this->minutes[$i]['description']);
$this->minutes[$i]['description'] = str_replace(" ", " - ", $this->minutes[$i]['description']);
$this->minutes[$i]['description'] = str_replace("&", "&", $this->minutes[$i]['description']);
$this->minutes[$i]['description'] = str_replace(" ", "...", $this->minutes[$i]['description']);

$this->committeeMinutes .= '<li><a href="/client_files/'.$this->path."/minutes/".$this->minutes[$i]['filename'].'">';
$this->committeeMinutes .= $this->minutes[$i]['description']."</a></li>\n";
}

$this->committeeMinutes .= "</ul>\n";
}// end formatMinutes

function fetchCalendar() {

$sql = "SELECT * FROM `calendar` WHERE committee_id = ".$this->committeeId."
AND UNIX_TIMESTAMP(CONCAT_WS('-', startYear, startMonth, startDay )) > UNIX_TIMESTAMP(NOW())
ORDER BY UNIX_TIMESTAMP(CONCAT_WS('-', startYear, startMonth, startDay )) Asc LIMIT 1";

$results = mysql_query($sql);

if( mysql_num_rows($results) == 0 ) {
$this->calendar = "There are no upcoming meetings for this committee, check back later.";
return false;
}

while( $row = mysql_fetch_assoc($results) ) {
$this->calendar = $row;
}
}// end fetchCalendar

function formatCalendar() {

if( !is_array($this->calendar) ) {
$this->committeeCalendar = '<h3>Next Meeting: &nbsp;</h3><p>'.$this->calendar."</p>";
return false;
}

$date = date("F j, Y",
strtotime($this->calendar['startYear'].'-'.$this->calendar['startMonth'].'-'.$this->calendar['startDay']));

$this->committeeCalendar = '<h3>Next Meeting: &nbsp;</h3>';
$this->committeeCalendar .= '<p><strong>'.$date.'</strong> -
<a href="mailto:rsvp@*********.org?subject=RSVP: '.$this->committeeName.'; '.$date.'">R.S.V.P</a>
for this meeting.</p>';

}//end formatCalendar

function fetchGoals() {

$sql = "SELECT * FROM `goals` WHERE committee_id = ".$this->committeeId." ORDER BY `dateAdded` ASC";
$results = mysql_query($sql);

if( mysql_num_rows($results) == 0 ) {
$this->goals = ".";
return false;
}

while($row = mysql_fetch_assoc($results) ) {
$this->goals[] = $row;
}
}//end fetchGoals

function formatGoals() {

if( $this->committeeGoalHeader != "" && is_array($this->goals) ) {

$this->committeeGoals = '<h3>'.$this->committeeGoalHeader.':</h3><ul>';

for( $i = 0; $i < sizeof($this->goals); $i++ ) {
$this->committeeGoals .= '<li>'.$this->goals[$i]['goal']."</li>\n";
}

$this->committeeGoals .= ' </ul>';

} else {
$this->committteGoals = "";
}
}//end formatGoals

function fetchMembers() {

$sql = "SELECT * FROM `members` WHERE committee_id = ".$this->committeeId." ORDER BY `school` ASC";
$results = mysql_query($sql);

if( mysql_num_rows($results) == 0 ) {
$this->members = ".";
return false;
}

while($row = mysql_fetch_assoc($results) ) {
$this->members[] = $row;
}
}//end fetchMembers

function formatMembers() {

if( !is_array($this->members) ) {
$this->committeeMembers = "";
return;
}

$this->committeeMembers = '
<table class="memberTable" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><p><b>Name</b></p></td>
<td><p><b>Email</b></p></td>
<td><p><b>District</b></p></td>
<td><p><b>School</b></p></td>
</tr>';

for( $i = 0; $i < sizeof($this->members); $i++ ) {

$this->committeeMembers .= '
<tr>
<td><p class="cm_name">'.$this->members[$i]['name'].'</p></td>
<td><p><a href="mailto:'.strtolower($this->members[$i]['email']).'">'.strtolower($this->members[$i]['email']).'</a></p></td>
<td><p>'.$this->members[$i]['district'].'</p></td>
<td><p>'.$this->members[$i]['school'].'</p></td>
</tr>'."\n";

}
$this->committeeMembers .= "</table>\n";
}//end formatMembers



}

?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined property: error

Post by social_experiment »

I called the 'display()' method, and only got an error about the missing file (includes/class.db.php). I commented it out and then ran the page again, i didn't receive any error. If you do define the property in the class, it just echo's it on the page. It's possibly that it could have something to do with what is inside class.db.php. Could you paste the code or add the file?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
rdo
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 9:36 pm

Re: Undefined property: error

Post by rdo »

Code: Select all

<?php
 
class database {
 
    var $connection;
    var $host;
    var $username;
    var $password;
    var $databaseName;
 
    function database() {
    
        $this->host = "localhost";
        $this->username = "*******";
        $this->password = "****";
        $this->databaseName = "oec";
        
        $this->connect();
    
    
    }
    
    function connect() {
    
        $this->connection = mysql_connect($this->host, $this->username, $this->password );
        mysql_select_db($this->databaseName, $this->connection);
    
    }
    
    function disconnect() {
    
        mysql_close($this->connection);
    }
 
 
}
?>
User avatar
a.heresey
Forum Commoner
Posts: 59
Joined: Wed Dec 13, 2006 7:31 pm
Location: Chesapeake, VA, US

Re: Undefined property: error

Post by a.heresey »

Check what the database is giving you. You have to run setValues() or fetchCommittee() before you can run display().
rdo
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 9:36 pm

Re: Undefined property: error

Post by rdo »

a.heresey wrote:Check what the database is giving you. You have to run setValues() or fetchCommittee() before you can run display().
Can you please explain that more? I am familiar SQL but not MySQL or php. What is "setValues" and "fetchCommittee"? I can view the contents of the DB's in phpMyAdmin if your needing to know the DB structure.
User avatar
a.heresey
Forum Commoner
Posts: 59
Joined: Wed Dec 13, 2006 7:31 pm
Location: Chesapeake, VA, US

Re: Undefined property: error

Post by a.heresey »

the way your script is written you must run the fetchCommittee() method to define the properties before you can access them with the display() method. The fetchCommittee() method is part of the code you posted. If you are running that method first and still not getting anything I recommend you echo out what your database call gives you to make sure that it is giving you only one result because that could cause fetchCommittee() to fail.
rdo
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 9:36 pm

Re: Undefined property: error

Post by rdo »

Ok, I think i understand what you were suggesting. Please remember this is a functional site that was made by someone else and this is the first time I have done anything with php.

I changed:
//Goals
$this->fetchGoals();
$this->formatGoals();
to:
//Goals
$this->fetchGoals();
$this->formatGoals();
echo $this->committeegoals;
this simply gave me the same error I was getting before:
Notice: Undefined property: committee::$committeegoals in C:\wamp\www\includes\class.committee.php on line 26

P.S. there were some other errors on the site which I have been working on trying to fix. A couple of them I determined to be caused by the site using command that are now considered outdated. Apparently when the site was running on the old server, It was using a older version of php then the new server uses. Does anyone see anything on this page that could possibly also be outdated/incorrect which could cause this problem? This site has been running for a year without problem on the old server and just now having problems after moving it to a new machine.
User avatar
a.heresey
Forum Commoner
Posts: 59
Joined: Wed Dec 13, 2006 7:31 pm
Location: Chesapeake, VA, US

Re: Undefined property: error

Post by a.heresey »

Where is the code where you are calling this class? You need to call setValues() before calling display.
rdo
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 9:36 pm

Re: Undefined property: error

Post by rdo »

That code is in the SetValues. see the full code above
rdo
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 9:36 pm

Re: Undefined property: error

Post by rdo »

Can someone please help me with this!
Post Reply