gpt4 book ai didi

php - 我是 PHP 新手,收到此错误 :

转载 作者:太空宇宙 更新时间:2023-11-03 11:56:48 25 4
gpt4 key购买 nike

Notice: Use of undefined constant msg - assumed 'msg' in C:\wamp\www\Stanly 1 - Copy\index.php on line 48 Log In

Notice: Use of undefined constant msg - assumed 'msg' in C:\wamp\www\Stanly 1 - Copy\index.php on line 50

Notice: Use of undefined constant msg - assumed 'msg' in C:\wamp\www\Stanly 1 - Copy\index.php on line 50

Notice: Use of undefined constant msg - assumed 'msg' in C:\wamp\www\Stanly 1 - Copy\index.php on line 50

我在网上找不到任何解决方案,所以也许有人可以帮助我。

代码如下:

if($_GET[msg] != ""){ ?>
<tr>
<td colspan="2" style="color:#FF0000;" align="center"><?php if ($_GET[msg] == 1) {
echo "Login failed.";
} elseif ($_GET[msg] == 2) {
echo "Only Administrator allowed.";
} elseif ($_GET[msg] == 3) {
echo "You have logged out.";
} ?> </td>
</tr>
<?php } ?>
<tr>
<td width="120" class="style23">Username</td>
<td width="164" class="style19">&nbsp;<input type="text" name="username" /></td>
</tr>
<tr>
<td class="style23">Password</td>
<td class="style19">&nbsp;<input type="password" name="password" /></td>
</tr>
<tr>
<td class="style19" colspan="2" align="center">&nbsp;
<input type="submit" name="login" value="Log in" />
</td>
</tr>
</table>

在那之后我所做的(或者至少我正在尝试)是更新 MySQL 中的表。

感谢您花时间回答我。干杯!

最佳答案

您的问题是未加引号的字符串。

$_GET[msg]

应该是

$_GET['msg']

因为您没有使用引号引起来,PHP 会尝试找到常量 msg,但找不到,并将其解释为字符串,这正是您首先想要的。

只要没有定义常量 msg,您的代码就会显示该通知,但会按预期运行。

您的代码变为:

if($_GET['msg'] != ""){ ?>
<tr>
<td colspan="2" style="color:#FF0000;" align="center"><?php if($_GET['msg'] == 1){ echo "Login failed."; } elseif($_GET['msg'] == 2){ echo "Only Administrator allowed."; }elseif($_GET['msg'] == 3){ echo "You have logged out."; }?> </td>
</tr>
<?php } ?>
<tr>
<td width="120" class="style23">Username</td>
<td width="164" class="style19">&nbsp;<input type="text" name="username" /></td>
</tr>
<tr>
<td class="style23">Password</td>
<td class="style19">&nbsp;<input type="password" name="password" /></td>
</tr>
<tr>
<td class="style19" colspan="2" align="center">&nbsp;
<input type="submit" name="login" value="Log in" />
</td>
</tr>

关于php - 我是 PHP 新手,收到此错误 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32114485/

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