0

当用户输入系统中未找到的电子邮件地址时,我试图显示错误。到目前为止,即使电子邮件与其他正确的回显结果一起在系统中,它也会在结果页面上回显。

<?php
$db = new mysqli(" ", " ", " ", "volsched");

if ($db->connect_errno) {
          echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
          }

$stmt = $db->prepare('UPDATE volConfirm SET confirmed = "YES" WHERE email = ?');
if (!$mysqli->error) {
   printf("Errormessage: Email not in system %s\n", $mysqli->error);
}

$stmt->bind_param('s', $_POST['email']);
$stmt->execute();

$stmt = $db->prepare('SELECT agreename, position, shift_times, confirmed from volConfirm WHERE email = ?');

$stmt->bind_param('s', $_POST['email']);

$stmt->execute();
$stmt->bind_result($agreeName, $position, $shift_times, $confirmed);

    while ($stmt->fetch()) {
// construct your output here using $row to access database record
echo "<h2>" . $agreeName . "</h2>";
echo "<p> You have been assigned as a volunteer for:" . $position . "</p>";
echo "<p>Your shift times are scheduled for:" . $shift_times . "</p>";
echo "<p>Your shift has been confirmed:" . $confirmed . "</p>";
 }

?>
4

1 回答 1

0

我最终使用了一些 JS 来根据电子邮件地址是否有效来控制显示哪些 div。

if($('#returned').length > 0) {
$('.noEmail').hide();
$('#volunteerResults').show()
 }});

因此,如果电子邮件地址不在系统中,则根据结果显示或隐藏包含“电子邮件不在系统中”的 .noEmail div

$stmt = $db->prepare('UPDATE volConfirm SET confirmed = "YES" WHERE email = ?');


$stmt->bind_param('s', $_POST['email']);
$stmt->execute();

$stmt = $db->prepare('SELECT agreeName, position, shift_times, confirmed from volConfirm WHERE email = ?');

$stmt->bind_param('s', $_POST['email']);
于 2012-05-20T18:46:43.237 回答