Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7308471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:33:43+00:00 2026-05-28T23:33:43+00:00

So in this code all I am trying to do is create a view

  • 0

So in this code all I am trying to do is create a view chores page.
I have created a chore class and a choreDAO class, which my view_chores page is calling from.

I have used the exact same code with other pages such as view_members and they also have the other two classe and they work fine!

The error occurs in the view_chores.php file below; this line of code:

echo "<b>Title:</b> " . $chore->getChoreName() . "<br />";

any help would be great. thank you!

Here is my view_chores.php page.

<?php
ob_start();
require_once 'includes/Member.php';
require_once 'includes/MemberDAO.php';
require_once 'includes/Chore.php';
require_once 'includes/ChoreDAO.php';
require_once 'includes/session.php';
confirm_logged_in(); // needs to come before any html because it does a redirect
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        require 'toolbar.php';
        $member = ($_SESSION['member']);

        $choreDAO = new ChoreDAO();
        $chores = $choreDAO->getChores();


        echo "<p>Hello " . $member->getFN() . "</p>";
        echo "<p>These are the current chores:  </p>";


        foreach ($chores as $chore) {
           echo "<b>Title:</b> " . $chore->getChoreName() . "<br />";
           echo "</p>";


        }


        echo $display; ?>
        <a href="add_chore_form.php">Add Chore?</a>



    </body>
</html>

<?php ob_flush(); ?>

Here is my Chore.php

    <?php
class Chore {
private $id;
private $chore_name;



public function __construct($i, $chore_name) {
    $this->id = $i;
    $this->chore_name = $chore_name;


}
public function getId() { return $this->id; }
public function getChoreName() { return $this->chore_name; }



public function setId($i) { $this->id = $i; }
public function setChoreName($cn) { $this->ChoreName = $cn; }


}
?>

and here is my ChoreDAO.php

    <?php
     require_once 'DAO.php';

     class ChoreDAO extends DAO {

    public function __construct() {
        parent::__construct();
    }

    public function insert($chore) {
        if (!isset($chore)) {
            throw new Exception("Chore required");
        }
        $sql = "INSERT INTO Chore(chore_name) VALUES (?)";
        $params = array($chore->getChoreName());
        $stmt = $this->link->prepare($sql);
        $status = $stmt->execute($params);
        if ($status != true) {
            $errorInfo = $stmt->errorInfo();
            throw new Exception("Could not save Chore: " . $errorInfo[2]);
        }

        $sql = "SELECT LAST_INSERT_ID()";
        $stmt = $this->link->prepare($sql);
        $status = $stmt->execute();
        if ($status != true) {
            $errorInfo = $stmt->errorInfo();
            throw new Exception("Could not retrieve new chore's id: " . $errorInfo[2]);
        }
        $row = $stmt->fetch();
        $id = $row[0];
        $chore->setId($id);
    }

    public function delete($chore) {
        if (!isset($chore)) {
            throw new Exception("Chore required");
        }
        $id = $chore->getId();
        if ($id == null) {
            throw new Exception("Chore id required");
        }
        $sql = "DELETE FROM Chore WHERE id = ?";
        $params = array($chore->getId());
        $stmt = $this->link->prepare($sql);
        $status = $stmt->execute($params);
        if ($status != true) {
            $errorInfo = $stmt->errorInfo();
            throw new Exception("Could not delete Chore: " . $errorInfo[2]);
        }
    }

    public function update($chore) {
        if (!isset($chore)) {
            throw new Exception("Chore required");
        }
        $id = $chore->getId();
        if ($id == null) {
            throw new Exception("Chore id required");
        }
        $sql = "UPDATE Chore SET chore_name = ? WHERE id = ?";
        $params = array($chore->getChoreName());
        $stmt = $this->link->prepare($sql);
        $status = $stmt->execute($params);
        if ($status != true) {
            $errorInfo = $stmt->errorInfo();
            throw new Exception("Could not update Chore: " . $errorInfo[2]);
        }
    }

    public function getChore($id) {
        $sql = "SELECT * FROM Chore WHERE id = ?";
        $params = array($id);
        $stmt = $this->link->prepare($sql);
        $status = $stmt->execute($params);
        if ($status != true) {
            $errorInfo = $stmt->errorInfo();
            throw new Exception("Could not retrieve Chore: " . $errorInfo[2]);
        }

        $chore = null;
        if ($stmt->rowCount == 1) {
            $row = $stmt->fetch();
            $id = $row['id'];
            $chore_name = $row['house_name'];

            $chore = new ChoreDAO($id, $chore_name);
        }
        return $chore;
    }

    public function getChores() {
        $sql = "SELECT * FROM  Chore";
        $stmt = $this->link->prepare($sql);
        $status = $stmt->execute();
        if ($status != true) {
            $errorInfo = $stmt->errorInfo();
            throw new Exception("Could not retrieve chores: " . $errorInfo[2]);
        }

        $chores = array();
        $row = $stmt->fetch();
        while ($row != null) {
            $id = $row['id'];
            $chore_name = $row['chore_name'];

            $chore= new ChoreDAO($i, $chore_name);
            $chores[$id] = $chore;

            $row = $stmt->fetch();
        }
        return $chores;
    }
   }
   ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:33:43+00:00Added an answer on May 28, 2026 at 11:33 pm

    In your ChoreDAO class getChores() method, you are using this:

    $chore= new ChoreDAO($i, $chore_name);
    

    Where it should be:

    $chore= new Chore($i, $chore_name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I am trying to code a Connect4 game. For this, I have created
I have this code which gets WP posts, but it gets all the posts
I have this code: $li = $(li, this) Which is selecting all of the
Problem Hello all! I have this code which takes my jpg image loops through
I've been trying to get this code to work for hours! All I need
Hi all I have this code to check if an item from a textbox
I have this code to connect to Active Directory and get all the groups
In a MVC project am trying to create a view which has the Title
here i have this code that i'm trying where openingHoursView.ohLocation has two values value1
I'm trying to create an 'archive'-page for my blog. It should list all blog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.