1

我有一个时间表数据库,志愿者可以在其中检查他们的班次。我将通过电子邮件向他们发送一个链接,该链接指向他们将电子邮件地址输入 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>";
    }
4

1 回答 1

1

您需要执行以下操作:

  1. 在您的志愿者表中添加一个新列

    ALTER TABLE Volunteers ADD COLUMN Confirmed BOOLEAN NOT NULL DEFAULT FALSE;
    
  2. 让提交页面中的 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
    }
    
  3. 在未来的某个时间,获取所有尚未访问该页面的用户的列表:

    SELECT Email FROM Volunteers WHERE Confirmed = FALSE;
    
于 2012-04-24T13:59:14.597 回答