我有一个时间表数据库,志愿者可以查看他们的班次。我将通过电子邮件向他们发送一个指向页面的链接,在该页面中,他们将电子邮件地址输入HTML表单以访问此信息。
有没有办法可以跟踪哪些电子邮件被查询,以便我可以重新发送日程安排链接给那些没有访问过数据库的人?
如果有必要,我可以在结果中添加一个额外的“已确认”复选框,并更新数据库。我喜欢这个想法,但我不确定如何实施(或者该行动的术语)。
编辑:这是我用来实现的代码。但是我没有在确认栏中得到结果。
$db = new mysqli("host", "user", "pass", "db");
$stmt = $db->prepare('UPDATE volConfirm SET confirmed = TRUE WHERE email = ?');
$stmt->bind_param('s', $_POST['email']);
$stmt->execute();
$stmt = $db->prepare('SELECT * from volConfirm WHERE email = ?');
$stmt->bind_param('s', $_POST['email']);
$result = $stmt->get_result();
while ($row = $result->fetch_array(MYSQLI_NUM)) {
// construct your output here using $row to access database record
echo "<h2>" . $row['agreeName'] . "</h2>";
echo "<p> You have been assigned as a volunteer for:" . $row['position'] . "</p>";
echo "<p>Your shift times are scheduled for:" . $row['shift_times'] . "</p>";
echo "<p>Your shift has been confirmed:" . $row['confirmed'] . "</p>";
}
答案 0 :(得分:1)
你需要做一些事情:
在志愿者表格中添加新列
ALTER TABLE Volunteers ADD COLUMN Confirmed BOOLEAN NOT NULL DEFAULT FALSE;
让提交页面中的PHP更新该列:
UPDATE Volunteers SET Confirmed = TRUE WHERE Email = 'foo@bar.com';
在您的代码段中:
$db = new mysqli("dbhostname", "username", "password", "dbschema");
$stmt = $db->prepare('UPDATE volConfirm SET confirmed = TRUE WHERE email = ?');
$stmt->bind_param('s', $_POST['email']);
$stmt->execute();
$stmt = $db->prepare('SELECT * from volConfirm WHERE email = ?');
$stmt->bind_param('s', $_POST['email']);
$result = $stmt->get_result();
while ($row = $result->fetch_array(MYSQLI_NUM)) {
// construct your output here using $row to access database record
}
在将来的某个时间点,获取尚未访问该页面的所有用户的列表:
SELECT Email FROM Volunteers WHERE Confirmed = FALSE;