[英]Notice: Undefined index: register (error trying to make registration form?)
Notice: Undefined index: register on line 12.
注意:未定义的索引:在第12行注册。
This is some old website code that I'm going through to fix - I'm a noob at this. 这是一些旧的网站代码,我正在修复 - 我是一个菜鸟。
Originally I was using isset()
, but was forced to use null!==
最初我使用的是
isset()
,但是被迫使用null!==
if (isset($_SESSION['id'])) {
echo "<fieldset><legend><b>Error!</b></legend>";
echo "You are already logged in, therefore you can not register a new account!";
echo "</fieldset>";
} else {
if (null !== (!$_POST['register'])) {
echo "<fieldset><legend><b>Registration</b></legend><br />";
echo "Fill out all of these fields below in order to create a new account. This account will be used to enter, so you are advised not to share the information with anyone at all!<br /><br />";
echo "<form method=\"POST\">";
I expect to get a working registration form, but get this. 我希望得到一份工作登记表,但是得到这个。 I get the same undefined index error in other files as well in similar scenarios.
在类似的场景中,我在其他文件中也得到了相同的未定义索引错误。
Replace 更换
if (null !== (!$_POST['register']))
with 同
if (isset($_POST['register']) && $_POST['register'] != '') // to check not empty
or if (isset($_POST['register'])) 或if(isset($ _ POST ['register']))
Checking isset()
will check if the index is defined. 检查
isset()
将检查索引是否已定义。 If needed to check if any value exists in the index check $_POST['register'] != ''
如果需要检查索引中是否存在任何值,请检查
$_POST['register'] != ''
While using such scenarios it is always best to check if the index is present and the value in the index is defined. 在使用此类方案时,最好检查索引是否存在以及索引中的值是否已定义。 This will save a lot of headaches.
这将节省很多麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.