Php 带有$\u POST变量的未定义索引
使用此代码:Php 带有$\u POST变量的未定义索引,php,Php,使用此代码: $tstUsername = getValue($_POST['tstUsername']); $tstPassword = getValue($_POST['tstPassword']); if ($tstUsername !== false && $tstPassword !== false) { echo "New string added to database!"; haydayshops_mysql_query($c
$tstUsername = getValue($_POST['tstUsername']);
$tstPassword = getValue($_POST['tstPassword']);
if ($tstUsername !== false && $tstPassword !== false) {
echo "New string added to database!";
haydayshops_mysql_query($conn,"INSERT INTO table_accounts (username, password) VALUES >('$tstUsername','".sha1($tstPassword)."')");
}
代码工作正常,但当我打开错误模式时,我看到了以下严重错误:
注意:未定义索引:tstUsername in
未定义索引:签入密码
出现这些错误是因为您试图访问不存在的数组的键。在这里,您可以访问
$\u POST['tstUsername']
,但它似乎不存在于$\u POST
数据中。在代码中的其他地方使用名为checkPassword
的密钥,情况相同
为了避免这种情况,请在尝试访问该值之前使用检查它们是否已声明。您的问题是什么?您想知道吗?var_dump($_POST)可以确保postHi中有正确的数据,非常感谢您的解释。是的,这正是我要找的。只是不知道如何使用isset。谢谢:)