我有一个HTML登录页面,其中有一个管理员和用户的单选按钮,如果用户选择“管理员”,那么它应该重定向到管理员登录页面,如果他选择“用户”那么就应该到用户登录页面html重定向到php
如下面给出的HTML登录页面:
<!-- THE LOG IN PAGE -->
<div id="id01" class="modal">
<form name="login" id="login" class="modal-content animate" action="login.php" method="post">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<img src="images/avatar.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label><b>Email Id:</b></label>
<input type="text" placeholder="Enter Email Id" name="email" id="email" required>
<label><b>Password:</b></label>
<input type="password" placeholder="Enter Password" name="psw" id="psw" required>
<label><b>User Type:</b></label>
<table width="100%">
<tr>
<td><input type="radio" name="usertype" id="usertype" value="admin" required>ADMIN</td>
<td><input type="radio" name="usertype" id="usertype" value="user" required>USER</td>
</tr>
</table>
<button type="submit">Login</button>
<input type="checkbox" checked="checked"> Remember me
<span class="psw"><a href="#">Forgot password?</a></span>
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
</div>
</form>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event)
{
if (event.target == modal)
{
modal.style.display = "none";
}
}
</script>
</div>
为用户admin_login.php页面如下:
<?php
在session_start() ;
$ email = $ _ POST [“email”];
$ psw = $ _ POST [“psw”];
$ name =“”;
include'db_config.php';
$ sql =“SELECT name,password,email FROM admin_details where email ='$ email'”;
$ result = $ conn-> query($ sql);
如果($ result-> NUM_ROWS> 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
$name=$row['name'];
if($psw == $row['password'])
{
$_SESSION['name']=$name;
$_SESSION['email']=$email;
header('Location: admin_index.php');
}
else
{
echo '<script type="text/javascript">';
echo 'alert("WRONG PASSWORD ENTRY. TRY LOGGING IN AGAIN !!!");';
echo 'window.location.href = "admin_index.php";';
echo '</script>';
}
}
}
别的
{
echo '<script type="text/javascript">';
echo 'alert("You must REGISTER first and then LOGIN !!!");';
echo 'window.location.href = "admin_index.php";';
echo '</script>';
}
$ conn-> close();
>
其中是您的PHP脚本用于重定向? –
有两种方法,无论是使用Javascript或PHP(获取元素值,相应地进行比较和重定向) –
男人,这是痛苦的眼睛...请尝试扔它通过在线格式化器或东西,请。这一个是相当不错的,我想http://www.freeformatter.com/html-formatter.html –