Need to edit and delete using DAO
<p>I was wondering if anyone could help me with this problem i'm having.
I have a ReminderDAO class with methods to delete, edit, insert etc and a Reminder class with a constructor and get and sets.</p>

<p>I then have a a view reminders where it just lists all the reminders out.
I want to be able to add an edit and delete to this view page.</p>

<p>To use the delete and edit functions in my ReminderDAO class, i need to pass a reminder object through the function and i'm not quite sure how to do this.</p>

<p>If anyone could help me that would be of great help, i'm new to this language so i apologise if it's not great code.</p>

<p>Thank you in advance!</p>

<p><strong>Reminder DAO</strong>
    

<pre><code>class ReminderDAO extends DAO {

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

    public function insert($reminder) {
        if (!isset($reminder)) {
            throw new Exception("Reminder required");
        }
        $sql = "INSERT INTO Reminders(member_id, title, details, reminder_type) VALUES (?, ?, ?, ?)";
        $params = array($reminder-&gt;getMember_id(), $reminder-&gt;getTitle(), $reminder-&gt;getDetails(), $reminder-&gt;getType());
        $stmt = $this-&gt;link-&gt;prepare($sql);
        $status = $stmt-&gt;execute($params);
        if ($status != true) {
            $errorInfo = $stmt-&gt;errorInfo();
            throw new Exception("Could not save Reminder: " . $errorInfo[2]);
        }

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

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

    public function update($reminder) {
        if (!isset($reminder)) {
            throw new Exception("Reminder required");
        }
        $id = $reminder-&gt;getId();
        if ($id == null) {
            throw new Exception("Reminder id required");
        }
        $sql = "UPDATE Reminders SET member_id = ?, title = ?, details = ?, reminder_type = ? WHERE id = ?";
        $params = array($reminder-&gt;getMember_id(), $reminder-&gt;getTitle(), $reminder-&gt;getDetails(), $reminder-&gt;getType());
        $stmt = $this-&gt;link-&gt;prepare($sql);
        $status = $stmt-&gt;execute($params);
        if ($status != true) {
            $errorInfo = $stmt-&gt;errorInfo();
            throw new Exception("Could not update Reminder: " . $errorInfo[2]);
        }
    }

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

        $reminder = null;
        if ($stmt-&gt;rowCount == 1) {
            $row = $stmt-&gt;fetch();
            $id = $row['id'];
            $member_id = $row['member_id'];
            $title = $row['title'];
            $details = $row['details'];
            $type = $row['reminder_type'];
            $reminder = new ReminderDAO($id, $member_id, $title, $details, $type);
        }
        return $reminder;
    }

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

        $reminders = array();
        $row = $stmt-&gt;fetch();
        while ($row != null) {
            $id = $row['id'];
            $member_id = $row['member_id'];
            $title = $row['title'];
            $details = $row['details'];
            $type = $row['reminder_type'];


            $reminder = new Reminder($id, $member_id, $title, $details,  $type);
            $reminders[$id] = $reminder;

            $row = $stmt-&gt;fetch();
        }
        return $reminders;
    }
}
?&gt;
</code></pre>

<p><strong>Reminder Class</strong></p>

<pre><code>&lt;?php
class Reminder {
    private $id;
    private $member_id;
    private $title;
    private $details;
    private $reminder_type;


    public function __construct($i, $m_id, $title, $det, $type) {
        $this-&gt;id = $i;
        $this-&gt;member_id = $m_id;
        $this-&gt;title = $title;
        $this-&gt;details = $det;
        $this-&gt;reminder_type = $type;
    }
    public function getId() { return $this-&gt;id; }
    public function getMember_id() { return $this-&gt;member_id; }
    public function getTitle() { return $this-&gt;title; }
    public function getDetails() { return $this-&gt;details; }
    public function getType() { return $this-&gt;reminder_type; }


    public function setId($i) { $this-&gt;id = $i; }
    public function setMember_id($mID) { $this-&gt;member_id = $mID; }
    public function setTitle($t) { $this-&gt;title = $t; }
    public function setDetails($d) { $this-&gt;details = $d; }
    public function setType($type) { $this-&gt;reminder_type = $type; }


}
?&gt;
</code></pre>

<p><strong>View Reminders</strong></p>

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

        $reminderDAO = new ReminderDAO();
        $reminders = $reminderDAO-&gt;getReminders();



        echo "&lt;p&gt;Hello " . $member-&gt;getFN() . "&lt;/p&gt;";
        echo "&lt;p&gt;These are the current reminders:  &lt;/p&gt;";


        foreach ($reminders as $rem) {
            echo "&lt;b&gt;Title:&lt;/b&gt; " . $rem-&gt;getTitle() . "&lt;br /&gt;";
            echo "&lt;b&gt;Details:&lt;/b&gt; " . $rem-&gt;getDetails() . "&lt;br /&gt;";
            echo "&lt;b&gt;Type: &lt;/b&gt;" . $rem-&gt;getType() . "&lt;br /&gt;";



           echo "&lt;/p&gt;";

        }


        echo $display; ?&gt;
        &lt;a href="add_reminder_form.php"&gt;Add Reminder?&lt;/a&gt;



    &lt;/body&gt;
&lt;/html&gt;
&lt;?php ob_flush(); ?&gt;
</code></pre>

<p><strong>edit_reminder_form.php class</strong></p>

<pre><code>&lt;?php
ob_start();
require_once 'includes/session.php';
require_once 'includes/Member.php';
require_once 'includes/MemberDAO.php';
require_once 'includes/Reminder.php';
require_once 'includes/ReminderDAO.php';
require_once 'includes/session.php';
confirm_logged_in(); // needs to come before any html because it does a redirect
?&gt;

&lt;?php

 $reminderDAO = new ReminderDAO();
 $reminder = $reminderDAO-&gt;getReminder($_GET['id']);




?&gt;

&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Edit Reminder&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;

        &lt;table&gt;
            &lt;tr&gt;
            &lt;td&gt;
            &lt;h2&gt;Edit Reminder&lt;/h2&gt;
             &lt;?php if (isset($_GET['errorMessage'])) echo "&lt;p&gt;".$_GET['errorMessage']."&lt;/p&gt;"; ?&gt;
               &lt;form action="edit_reminder.php" method="POST"&gt;
                   Title: &lt;input type="text" name="title" value="&lt;?php $reminder-&gt;getTitle(); ?&gt;" /&gt;&lt;br/&gt;
                   Details: &lt;input type="text" name="details" value="&lt;?php $reminder-&gt;getDetails()?&gt; " /&gt;&lt;br/&gt;

                   &lt;select name="reminder_type" value="&lt;?php $reminder-&gt;getType();?&gt;"&gt;
                &lt;option value="Choose"&gt;Please choose a reminder type!&lt;/option&gt;
                &lt;option value="Bill"&gt;Bill&lt;/option&gt;
                &lt;option value="Shopping"&gt;Shopping&lt;/option&gt;
                &lt;option value="Event"&gt;Event&lt;/option&gt;
                &lt;option value="Birthday"&gt;Birthday&lt;/option&gt;
                &lt;option value="Other"&gt;Other&lt;/option&gt;
                &lt;/select&gt;
                &lt;br /&gt;
                &lt;input type="submit" name="reminder" value="Edit Reminder" /&gt;
               &lt;/form&gt;
            &lt;br /&gt;
            &lt;a href ="view_reminders.php"&gt; Cancel &lt;/a&gt;
            &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/body&gt;
    &lt;?php
    //5.Close connection
    if(isset($connection)) {
     mysql_close($connection);
    }
    ?&gt;
&lt;/html&gt;

&lt;?php ob_flush(); ?&gt;
</code></pre>
