我正在尝试创建简单的HTML表单/ PHP脚本,用户可以输入信息,我想要做的只是在屏幕上显示如果成功或按下按钮重置给你消息它被删除。当我正在学习PHP时,我正在尝试做一些项目,但我无法弄明白。
<title>Login Page</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$lastName = $_POST['lastName'];
$submit="Your name and last name is input in!";
echo $submit;
}
if(isset($_POST['reset'])){
echo "Yours data are erased!";
}
?>
<h2>Login Page</h2>
<p>Please input your info in form bellow:</p>
<form name="login" method="post" action="index.php">
<table border="0">
<tr>
<td>Name: </td>
<td><input type="text" name="name" size="20" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="password" name="lastName" size="20" /></td>
</tr>
</table>
<input type="submit" name="submitButton" value="Submit" />
<input type="reset" name="resetButton" value="Reset" />
</form>
</body>
</html>
答案 0 :(得分:0)
您需要将if(isset($_POST['submit'])){
更改为if(isset($_POST['submitButton'])){
并将重置更改为<input type="submit" name="resetButton" value="Reset" />
,并通过名称resetButton
如果我在哪里,我会检查if(isset($_POST['submitButton'])){
是否为entres,因为按下submitButton会回显你的消息。
签入
if(isset($_POST['submitButton'])){
$name = $_POST['name'];
$lastName = $_POST['lastName'];
if (!empty($name) && !empty($lastName)) {
$submit="Your name and last name is input in!";
echo $submit;
} else {
echo 'Show this line that there is not entery in $name or $lastName';
}
}
答案 1 :(得分:0)