我使用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();
?>
答案 0 :(得分:2)
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">
它会在加载时重定向到另一个页面。
答案 1 :(得分:1)
使用header()
,并且在header function
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');;
}
}