我设计了一个使用HTML和CSS的表单,并使用phpMyAdmin作为后端,我可以在其中保存用户数据并将其用于登录目的。我已经成功连接了phpMyAdmin,成功保存数据并在登录页面中验证。
现在我的问题是,如果登录成功,它必须加载HTML页面empaccess.html
。我不知道如何在PHP中做到这一点。
这是我的PHP代码(empcheck.php):
<?php
$a=$_POST['text3'];
$b=$_POST['text4'];
mysql_connect("localhost","root","","crm");
mysql_select_db("crm") or die("Error in Connection");
if (empty($_POST['text3']) && empty($_POST['text4']))
{
echo "<h1><center>PLEASE ENTER YOUR USERNAME AND PASSWORD</center></h1>";
exit();
}
$query="SELECT * from emmreg WHERE username='$a'";
$result=mysql_query($query);
if($result)
{
$row=mysql_fetch_assoc($result) or die("");
$uname=$row['username'];
$pwd=$row['password'];
if($a==$uname && $b==$pwd)
{
echo "Success";
//header('location:index.html');
}
else
{
echo "INCORRECT PASSWORD";
}
}mysql_close();
?>
PHP:
header('Location: http://example.com/page.php');
Javascript:
<script type="text/javascript">
window.location = "http://www.example.com/";
</script>
.HTML:
<meta http-equiv="Refresh" content="seconds; url=URL">
它将在加载时重定向到另一个页面。
使用header()
,不要尝试回显或尝试在标头函数之前获取任何输出
if($result)
{
$row=mysql_fetch_assoc($result) or die("");
$uname=$row['username'];
$pwd=$row['password'];
if($a==$uname && $b==$pwd)
{
header('location:empaccess.html');
}
else
{
header('location:index.html');;
}
}