I’m trying to show an error when the user enters an email address that’s not found in the system. So far it either echoes on the results page even if the email is in the system along with the other correct echo’d results.
<?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>";
}
?>
I wound up using a bit of JS to control what divs are displayed based on whether or not the email address was valid.
So if the email address isn’t in the system, the .noEmail div which contains “Email not in system” is shown or hidden based on results