Php 需要使用DAO进行编辑和删除吗
我想知道是否有人能帮我解决这个问题。 我有一个带有删除、编辑、插入等方法的ReminderDAO类,还有一个带有构造函数、get和set的ReminderDAO类 然后我有一个视图提醒,它只是列出了所有的提醒。 我希望能够在此查看页面中添加编辑和删除 要在我的提醒道类中使用delete和edit函数,我需要通过该函数传递一个提醒对象,但我不太确定如何做到这一点 如果有人能帮助我,那将是一个很大的帮助,我是新的语言,所以我道歉,如果它不是伟大的代码 提前谢谢你 提醒道Php 需要使用DAO进行编辑和删除吗,php,Php,我想知道是否有人能帮我解决这个问题。 我有一个带有删除、编辑、插入等方法的ReminderDAO类,还有一个带有构造函数、get和set的ReminderDAO类 然后我有一个视图提醒,它只是列出了所有的提醒。 我希望能够在此查看页面中添加编辑和删除 要在我的提醒道类中使用delete和edit函数,我需要通过该函数传递一个提醒对象,但我不太确定如何做到这一点 如果有人能帮助我,那将是一个很大的帮助,我是新的语言,所以我道歉,如果它不是伟大的代码 提前谢谢你 提醒道 class Reminder
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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not save Reminder: " . $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 reminder's id: " . $errorInfo[2]);
}
$row = $stmt->fetch();
$id = $row[0];
$reminder->setId($id);
}
public function delete($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->getId();
if ($id == null) {
throw new Exception("Reminder id required");
}
$sql = "DELETE FROM Reminders WHERE id = ?";
$params = array($reminder->getId());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not delete reminder: " . $errorInfo[2]);
}
}
public function update($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->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->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve Reminder: " . $errorInfo[2]);
}
$reminder = null;
if ($stmt->rowCount == 1) {
$row = $stmt->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->link->prepare($sql);
$status = $stmt->execute();
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve reminders: " . $errorInfo[2]);
}
$reminders = array();
$row = $stmt->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->fetch();
}
return $reminders;
}
}
?>
提醒类
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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not save Reminder: " . $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 reminder's id: " . $errorInfo[2]);
}
$row = $stmt->fetch();
$id = $row[0];
$reminder->setId($id);
}
public function delete($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->getId();
if ($id == null) {
throw new Exception("Reminder id required");
}
$sql = "DELETE FROM Reminders WHERE id = ?";
$params = array($reminder->getId());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not delete reminder: " . $errorInfo[2]);
}
}
public function update($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->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->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve Reminder: " . $errorInfo[2]);
}
$reminder = null;
if ($stmt->rowCount == 1) {
$row = $stmt->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->link->prepare($sql);
$status = $stmt->execute();
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve reminders: " . $errorInfo[2]);
}
$reminders = array();
$row = $stmt->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->fetch();
}
return $reminders;
}
}
?>
<?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->id = $i;
$this->member_id = $m_id;
$this->title = $title;
$this->details = $det;
$this->reminder_type = $type;
}
public function getId() { return $this->id; }
public function getMember_id() { return $this->member_id; }
public function getTitle() { return $this->title; }
public function getDetails() { return $this->details; }
public function getType() { return $this->reminder_type; }
public function setId($i) { $this->id = $i; }
public function setMember_id($mID) { $this->member_id = $mID; }
public function setTitle($t) { $this->title = $t; }
public function setDetails($d) { $this->details = $d; }
public function setType($type) { $this->reminder_type = $type; }
}
?>
<?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
?>
<!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']);
$reminderDAO = new ReminderDAO();
$reminders = $reminderDAO->getReminders();
echo "<p>Hello " . $member->getFN() . "</p>";
echo "<p>These are the current reminders: </p>";
foreach ($reminders as $rem) {
echo "<b>Title:</b> " . $rem->getTitle() . "<br />";
echo "<b>Details:</b> " . $rem->getDetails() . "<br />";
echo "<b>Type: </b>" . $rem->getType() . "<br />";
echo "</p>";
}
echo $display; ?>
<a href="add_reminder_form.php">Add Reminder?</a>
</body>
</html>
<?php ob_flush(); ?>
<?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
?>
<?php
$reminderDAO = new ReminderDAO();
$reminder = $reminderDAO->getReminder($_GET['id']);
?>
<html>
<head>
<title>Edit Reminder</title>
</head>
<body>
<table>
<tr>
<td>
<h2>Edit Reminder</h2>
<?php if (isset($_GET['errorMessage'])) echo "<p>".$_GET['errorMessage']."</p>"; ?>
<form action="edit_reminder.php" method="POST">
Title: <input type="text" name="title" value="<?php $reminder->getTitle(); ?>" /><br/>
Details: <input type="text" name="details" value="<?php $reminder->getDetails()?> " /><br/>
<select name="reminder_type" value="<?php $reminder->getType();?>">
<option value="Choose">Please choose a reminder type!</option>
<option value="Bill">Bill</option>
<option value="Shopping">Shopping</option>
<option value="Event">Event</option>
<option value="Birthday">Birthday</option>
<option value="Other">Other</option>
</select>
<br />
<input type="submit" name="reminder" value="Edit Reminder" />
</form>
<br />
<a href ="view_reminders.php"> Cancel </a>
</td>
</tr>
</table>
</body>
<?php
//5.Close connection
if(isset($connection)) {
mysql_close($connection);
}
?>
</html>
<?php ob_flush(); ?>
查看提醒
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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not save Reminder: " . $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 reminder's id: " . $errorInfo[2]);
}
$row = $stmt->fetch();
$id = $row[0];
$reminder->setId($id);
}
public function delete($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->getId();
if ($id == null) {
throw new Exception("Reminder id required");
}
$sql = "DELETE FROM Reminders WHERE id = ?";
$params = array($reminder->getId());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not delete reminder: " . $errorInfo[2]);
}
}
public function update($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->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->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve Reminder: " . $errorInfo[2]);
}
$reminder = null;
if ($stmt->rowCount == 1) {
$row = $stmt->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->link->prepare($sql);
$status = $stmt->execute();
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve reminders: " . $errorInfo[2]);
}
$reminders = array();
$row = $stmt->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->fetch();
}
return $reminders;
}
}
?>
<?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->id = $i;
$this->member_id = $m_id;
$this->title = $title;
$this->details = $det;
$this->reminder_type = $type;
}
public function getId() { return $this->id; }
public function getMember_id() { return $this->member_id; }
public function getTitle() { return $this->title; }
public function getDetails() { return $this->details; }
public function getType() { return $this->reminder_type; }
public function setId($i) { $this->id = $i; }
public function setMember_id($mID) { $this->member_id = $mID; }
public function setTitle($t) { $this->title = $t; }
public function setDetails($d) { $this->details = $d; }
public function setType($type) { $this->reminder_type = $type; }
}
?>
<?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
?>
<!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']);
$reminderDAO = new ReminderDAO();
$reminders = $reminderDAO->getReminders();
echo "<p>Hello " . $member->getFN() . "</p>";
echo "<p>These are the current reminders: </p>";
foreach ($reminders as $rem) {
echo "<b>Title:</b> " . $rem->getTitle() . "<br />";
echo "<b>Details:</b> " . $rem->getDetails() . "<br />";
echo "<b>Type: </b>" . $rem->getType() . "<br />";
echo "</p>";
}
echo $display; ?>
<a href="add_reminder_form.php">Add Reminder?</a>
</body>
</html>
<?php ob_flush(); ?>
<?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
?>
<?php
$reminderDAO = new ReminderDAO();
$reminder = $reminderDAO->getReminder($_GET['id']);
?>
<html>
<head>
<title>Edit Reminder</title>
</head>
<body>
<table>
<tr>
<td>
<h2>Edit Reminder</h2>
<?php if (isset($_GET['errorMessage'])) echo "<p>".$_GET['errorMessage']."</p>"; ?>
<form action="edit_reminder.php" method="POST">
Title: <input type="text" name="title" value="<?php $reminder->getTitle(); ?>" /><br/>
Details: <input type="text" name="details" value="<?php $reminder->getDetails()?> " /><br/>
<select name="reminder_type" value="<?php $reminder->getType();?>">
<option value="Choose">Please choose a reminder type!</option>
<option value="Bill">Bill</option>
<option value="Shopping">Shopping</option>
<option value="Event">Event</option>
<option value="Birthday">Birthday</option>
<option value="Other">Other</option>
</select>
<br />
<input type="submit" name="reminder" value="Edit Reminder" />
</form>
<br />
<a href ="view_reminders.php"> Cancel </a>
</td>
</tr>
</table>
</body>
<?php
//5.Close connection
if(isset($connection)) {
mysql_close($connection);
}
?>
</html>
<?php ob_flush(); ?>
编辑\u提醒\u form.php类
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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not save Reminder: " . $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 reminder's id: " . $errorInfo[2]);
}
$row = $stmt->fetch();
$id = $row[0];
$reminder->setId($id);
}
public function delete($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->getId();
if ($id == null) {
throw new Exception("Reminder id required");
}
$sql = "DELETE FROM Reminders WHERE id = ?";
$params = array($reminder->getId());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not delete reminder: " . $errorInfo[2]);
}
}
public function update($reminder) {
if (!isset($reminder)) {
throw new Exception("Reminder required");
}
$id = $reminder->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->getMember_id(), $reminder->getTitle(), $reminder->getDetails(), $reminder->getType());
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->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->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve Reminder: " . $errorInfo[2]);
}
$reminder = null;
if ($stmt->rowCount == 1) {
$row = $stmt->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->link->prepare($sql);
$status = $stmt->execute();
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve reminders: " . $errorInfo[2]);
}
$reminders = array();
$row = $stmt->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->fetch();
}
return $reminders;
}
}
?>
<?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->id = $i;
$this->member_id = $m_id;
$this->title = $title;
$this->details = $det;
$this->reminder_type = $type;
}
public function getId() { return $this->id; }
public function getMember_id() { return $this->member_id; }
public function getTitle() { return $this->title; }
public function getDetails() { return $this->details; }
public function getType() { return $this->reminder_type; }
public function setId($i) { $this->id = $i; }
public function setMember_id($mID) { $this->member_id = $mID; }
public function setTitle($t) { $this->title = $t; }
public function setDetails($d) { $this->details = $d; }
public function setType($type) { $this->reminder_type = $type; }
}
?>
<?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
?>
<!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']);
$reminderDAO = new ReminderDAO();
$reminders = $reminderDAO->getReminders();
echo "<p>Hello " . $member->getFN() . "</p>";
echo "<p>These are the current reminders: </p>";
foreach ($reminders as $rem) {
echo "<b>Title:</b> " . $rem->getTitle() . "<br />";
echo "<b>Details:</b> " . $rem->getDetails() . "<br />";
echo "<b>Type: </b>" . $rem->getType() . "<br />";
echo "</p>";
}
echo $display; ?>
<a href="add_reminder_form.php">Add Reminder?</a>
</body>
</html>
<?php ob_flush(); ?>
<?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
?>
<?php
$reminderDAO = new ReminderDAO();
$reminder = $reminderDAO->getReminder($_GET['id']);
?>
<html>
<head>
<title>Edit Reminder</title>
</head>
<body>
<table>
<tr>
<td>
<h2>Edit Reminder</h2>
<?php if (isset($_GET['errorMessage'])) echo "<p>".$_GET['errorMessage']."</p>"; ?>
<form action="edit_reminder.php" method="POST">
Title: <input type="text" name="title" value="<?php $reminder->getTitle(); ?>" /><br/>
Details: <input type="text" name="details" value="<?php $reminder->getDetails()?> " /><br/>
<select name="reminder_type" value="<?php $reminder->getType();?>">
<option value="Choose">Please choose a reminder type!</option>
<option value="Bill">Bill</option>
<option value="Shopping">Shopping</option>
<option value="Event">Event</option>
<option value="Birthday">Birthday</option>
<option value="Other">Other</option>
</select>
<br />
<input type="submit" name="reminder" value="Edit Reminder" />
</form>
<br />
<a href ="view_reminders.php"> Cancel </a>
</td>
</tr>
</table>
</body>
<?php
//5.Close connection
if(isset($connection)) {
mysql_close($connection);
}
?>
</html>
<?php ob_flush(); ?>
编辑提醒
编辑提醒
标题:您可以将提醒的ID
发送到下一页,在那里您可以编辑/删除提醒
foreach ($reminders as $rem) {
echo "<b>Title:</b> " . $rem->getTitle() . "<br />";
echo "<b>Details:</b> " . $rem->getDetails() . "<br />";
echo "<b>Type: </b>" . $rem->getType() . "<br />";
echo "[<a href='edit.php?id=" . $rem->getID() . "'>Edit</a>] ";
echo "[<a href='delete.php?id=" . $rem->getID() . "'>Delete</a>] ";
echo "</p>";
}
foreach($rem形式的提醒){
echo“Title:”.$rem->getTitle().“
”;
echo“Details:”.$rem->getDetails().“
”;
echo“Type:”..rem->getType()“
”;
回声“[]”;
回声“[]”;
回声“”;
}
在edit.php
中,使用ID(例如$\u get['ID']
)获取提醒对象,使用提醒DAO从数据库加载数据,并创建一个填充有提醒值的表单。在该表单中,您还应该放置提醒id,以便当他将表单提交到保存更改
时,您可以识别已编辑的提醒。
保存更改后,您可以使用标题
功能将他重定向回提醒列表
类似地,在delete.php
中,您可以使用ID(例如$\u GET['ID']
)删除提醒,然后将用户重定向到提醒列表。非常感谢您的回答!但是,我不太确定edit.php中的含义。你能给我看一下我会用$_GET['id']在这行上写些什么吗?当然,如果你有时间的话。再次感谢您。您可以执行以下操作来检索通过GET发送的id为的提醒对象:$rementer\u to\u edit=$rementerdao->getrementer($\u GET['id'])
不幸的是,当我在下一页回显$_GET['id']时,当我在URL中单击“编辑”时,所有出现的都是“()”并且没有传递id。URL是什么样子的?id是否有值?(例如,localhost/my_project/edit.php?id=3
)哦。。我将代码更新为使用“$rem->getID()”
。让我知道它是否有效