一页上有两个登录表单和两个数据库表:admin( user
, pass
) 和 customer( fname
, laname
, email
, user
, pass
)。一份给客户,一份给管理员。想在里面处理两种形式login.php
尝试将用户名和密码存储在各自的变量中时,如何确定Submit
单击了哪个表单并从 login.php 中的两个表单访问user
和字段?pass
$_POST
像这样的东西?(进入 login.php):
if(//submit button in customer form was clicked){
$user=$_POST['customer_login']['user'];
$pass=$_POST['customer_login']['pass'];
}else{
//admin submit button was clicked
$user=$_POST['admin_login']['user'];
$pass=$_POST['admin_login']['pass'];
}
表格(HTML):
<form name="customer_login" method="post" action="login.php">
<h3>Customer:</h3>
Username: <input type="text" id="user" name="user"><br>
Password: <input type="password" id="pass" name="pass"><br>
<input type="submit" name="Submit" value="Sign in">
</form>
<form name="admin_login" method="post" action="login.php">
<h3>Admin:</h3>
Username: <input type="text" id="user" name="user"><br>
Password: <input type="password" id="pass" name="pass"><br>
<input type="submit" name="Submit" value="Sign in">
</form>