gpt4 book ai didi

php - undefined index 错误 - 为什么这仍然适用于错误抑制?

转载 作者:行者123 更新时间:2023-11-29 13:42:33 26 4
gpt4 key购买 nike

我在下面的代码中遇到错误“注意:未定义索引:srSend”。我有两个问题:

i) 如果我抑制错误,为什么这段代码可以工作? undefined index 是一个错误有什么关系吗? ii) 不管怎样,我怎样才能纠正这个错误?

<?php

//db connection
$mysqli = new mysqli("localhost", "root", "", "test");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}


if($_POST['srSend'] && $_POST['srEmail']) {
//check if email already taken
if ($stmt = $mysqli->prepare("SELECT user_pin FROM users WHERE user_email = ?")) {
$stmt->bind_param("s", strtolower($_POST['srEmail']));
$stmt->execute();
$stmt->bind_result($user_pin);
$stmt->fetch();
$stmt->close();
}

最佳答案

当您抑制错误时,您的代码仍然有效,因为它是“通知”。 PHP 中有不同级别的错误,您可以将 PHP 配置为仅显示某些类型的错误。以下是错误常量的完整列表:http://www.php.net/manual/fr/errorfunc.constants.php请注意,PHP 中默认禁用错误,因为您的代码仍然可以正常工作,但修复它们总是好的。

出现此通知是因为您尝试访问的索引不存在。您可以使用 isset() 来检查它们是否存在。

关于php - undefined index 错误 - 为什么这仍然适用于错误抑制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17884935/

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