我是初学者,我似乎无法让这个工作。有什么建议?请帮忙。
这是代码的一部分,保存在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>
您需要删除变量赋值中的isset,因此请更改为此。
$uname = $_POST['uname'];
$upass = $_POST['upass'];
$key = $_POST['key'];
如果设置了传递它的变量,则isset返回1(true),如果未设置,则返回0(false),这意味着所有变量都已设置,111已被打印。如果要在打印之前检查它们是否已设置,则需要额外的if语句。
也许是这样的东西,在打印之前检查它们是否都已设置好。
if (isset($_POST['uname'], $_POST['upass'], $_POST['key'])){
echo $uname;
echo $upass;
echo $key;
}