在mysqli中使用if / else的回显错误

时间:2012-04-25 06:35:19

标签: php error-handling mysqli echo

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

<?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>";
 }

?>

1 个答案:

答案 0 :(得分:0)

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

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

因此,如果电子邮件地址不在系统中,则.noEmail div包含&#34;电子邮件不在系统中&#34;根据结果​​显示或隐藏

$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']);