gpt4 book ai didi

php-mysql : different access page during login

转载 作者:行者123 更新时间:2023-11-29 07:05:00 29 4
gpt4 key购买 nike

我对这种登录方式感到困惑,尤其是对于某些用户登录后的不同访问页面。

我的数据库中有一些用户列表,例如:

  1. 管理员
  2. 用户

我想如果我以 admin 身份登录将定向到 input.php 如果我以 user 身份登录将定向到 index.php。我从一些网站上读到它必须使用 switch-case。但是,我仍然不清楚如何使用它。

$dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.": ".mysql_error());
$db=mysql_select_db("qdbase",$dbc) or die(_ERROR17.": ".mysql_error());

switch(postVar('action')) {
case 'submitlogin':
submitlogin(postVar('loguser'),postVar('logpass'));
mysql_close($dbc);
exit;
break;
}

function submitlogin($loguser,$logpass){
if(isset($loguser,$logpass)){
$myuser= mysql_real_escape_string($loguser);
$mypass= mysql_real_escape_string($logpass);
$sql= sprintf("SELECT * FROM admin WHERE user = '".$myuser."' AND password = '".$mypass."'", $myuser,$mypass);
$result = mysql_result($sql) or die (_ERROR26.": ".mysql_error());
if(mysql_num_rows($result) > 0){
session_register("loguser");
session_register("logpass");

switch $myuser{ //i dont know its correct or not
case 'admin':
header("location:input.php");
break;
case 'user':
header("location:index.php");
break;
}
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<META http-equiv='refresh' content='2; url=index.php'>
</head>
<title>Login success</title>
<body>
<h1>You logged in !</h1>
</body>
</html>
<?php
}else
{
header("location:log.php?msg=" . urlencode("Wrong Username or Password. Please retry"));
}
}else{
header("location:log.php?msg=" . urlencode("Please enter some username and password"));
}
}
?>

我遇到了这个错误:

PHP Warning:  mysql_result() expects at least 2 parameters, 1 given in /home/jeinqa/www/oqc/dolog.php on line 29 // on line 17 in this page

最佳答案

如果您要做的是将用户“admin”重定向到其他登录后页面,而不是

header("location:index1.php");    //i want to use switch-case in this part

你需要类似的东西

switch($loguser) {
case "admin" :
header("location:input.php");
break;
default: // this branch will run for all users other than 'admin'
header("location:index.php");

}

关于php-mysql : different access page during login,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7872427/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com