gpt4 book ai didi

php - 在MySQLi中使用if/else的回显错误

转载 作者:行者123 更新时间:2023-12-03 08:59:47 25 4
gpt4 key购买 nike

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

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

?>

最佳答案

我最终使用了一些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']);

关于php - 在MySQLi中使用if/else的回显错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10310508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com