我是一个初学者,我似乎无法使它正常工作。有什么建议么?请帮忙。
这是一部分代码,保存在php文件下
<?php
/**check if enter is pressed*/
if (isset($_POST['enter'])) {
/**set vars to results*/
$uname = isset($_POST['uname']);
$upass = isset($_POST['upass']);
$key = isset($_POST['key']);
/**print results*/
echo $uname;
echo $upass;
echo $key;
}
?>
<html>
<head>
<title>Chat gate</title>
</head>
<body align="center" valign="middle">
<form action="index.php" method="POST">
<tt>Enter your username</tt>
<input type = "text" name ="uname" required>
<tt>Enter your password:</tt>
<input type = "password" name = "upass" required>
<tt>Confirm key:</tt>
<input type = "text" name = "key" required>
<input type = "submit" name = "enter">
</form>
</body>
</html>
答案 0 :(得分:0)
您需要删除变量分配中的isset,因此请更改为此。
$uname = $_POST['uname'];
$upass = $_POST['upass'];
$key = $_POST['key'];
isset如果设置了传递的变量,则返回1(真),如果未设置,则返回0(假),这意味着已设置所有变量,并打印了111。如果要在打印之前检查它们是否已设置,则需要一个额外的if语句。
也许是这样的事情,以便在打印之前检查它们是否都已设置好。
if (isset($_POST['uname'], $_POST['upass'], $_POST['key'])){
echo $uname;
echo $upass;
echo $key;
}