首先,我对在网站中创建html和php代码非常陌生,所以如果这对这里的一些人来说似乎是一个微不足道的问题,请感谢我需要一点帮助。由于
我已经创建了一个登录用户名和密码的形式,只有一个用户(html形式)的工作结合到一个。php代码,它的工作完美。
当前:- 如果用户名和/或,它将不允许表单提交密码字段为空。
- 用户名和/或密码不正确显示回显("incorrect");文字在www.......com/login.php页面。
- 同时输入用户名和密码时正确地重定向到所需页面。
编辑想要的:
- 不显示echo ("incorrect");文本www……com/login.php页面。我想要显示"不正确"在HTML表单下面或内部。这节省了回到
谢谢。
HTML表单:
<fieldset>
<legend>Login</legend>
<label for="username" >UserName: </label>
<input type="text" id="username" name="username" required="true" />
<label for="pass" >Password:</label>
<input type="password" id="pass" name="pass" required="true"/>
<input type="submit" name="Submit" value="Submit" />
<include'login.php'/>
</fieldset>
</form>
login。
<?php
if(($_POST['username'] == "user1") && ($_POST['pass'] == "pass1"))
{
header("Location:http://www.yahoo.com");
}
else
{
echo ("incorrect");
}
?>
将表单嵌套在else条件中,然后在单个文件中处理登录
<?php
if(($_POST['username'] == "user1") && ($_POST['pass'] == "pass1"))
{
header("Location:http://www.yahoo.com");
}
else
{ ?>
<form name= "login" method="post" accept-charset='UTF-8'>
<fieldset>
<legend>Login</legend>
<label for="username" >UserName: </label>
<input type="text" id="username" name="username" required="true" />
<label for="pass" >Password:</label>
<input type="password" id="pass" name="pass" required="true"/>
<input type="submit" name="Submit" value="Submit" />
<include'login.php'/>
</fieldset>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "incorrect";
}
}
?>
代替
{
echo "incorrent";
}
类型:{
header("Location: loginform.php?error=incorrect");
}
在你的登录表单。php中像这样:
if(isset($_GET['error'])) {
echo $_GET['error'];
}
或者更好:您可以将表单保存为.php。然后以
开始if(isset($_POST))
你张贴逻辑。
然后显示表单。
,在输入变量中输入
<INPUT value="<?php echo isset($_POST['username']) ? $_POST['username'] :''; ?>">
编辑:总结:
<?php if(isset($_POST)) {
if(check) {
header("Location ...);
} else {
$error = 'incorrect';
}
} else {
$error = '';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>">
<fieldset>
<legend>Login</legend>
<label for="username" >UserName: </label>
<input type="text" value="<?php echo isset($_POST['username']) ? $_POST['username] : ''; ?>" id="username" name="username" required="true" />
<label for="pass" >Password:</label>
<input type="password" id="pass" name="pass" required="true"/>
<input type="submit" name="Submit" value="Submit" />
</fieldset>
</form>
<?php echo $error; ?>