duanjue2576 2015-01-19 11:14
浏览 58

使用php,mysql和复选框登录表单

I am working on a project in php, but I am stuck. I have a login form with 3 checkboxes and 2 text fields for username and password. Each checkbox represents a user, such as admin, student and lecturer. So when a user wants to login, he has to provide his username, password and check one of the checkboxes. So if the user is stored in the database as a student, he has to check the student checkbox and press the submit button. Then while processing, the system will check if this user is stored as student. If that is the case he can now login. Otherwise the login form comes back.

I have an array of checkboxes:

<Input type = "checkbox" name=" cool[] "value= "student">
<Input type = "checkbox" name=" cool[]" value=" admin">
<Input type = "checkbox" name=" cool[]" value=" lecturer">
<Input type = "submit" name= "submit" value= "login"> 

In the php part I have:

If (isset($_POST['submit'] ){
    $user=$_POST['textfield_value_username'] ;
    $pass=$_POST['textfield_value_passeord'] ;
    $check=$_POST['cool'] ;
    foreach ($check  as  $kio) {
        $d= "select * from table-name
            where = $user = 'value_from _db' , " 
        $pass= 'value_from_db' and $kio='value_in-db';
        if($d) {
            // do something...
       }
    }
}

This is an overview of the code. When I try it it doesn't work, but when I do select * and I use only $user and $pass it works. When I use only select * .... Where ... $Kio .. it works also. But when I combine all, it doesn't work and it doesn't give any error.

So, I don't know if I was clear, but this is all about the problem I have. I have been searching on internet but I got no result.

  • 写回答

2条回答 默认 最新

  • duangong0690 2015-01-19 11:20
    关注

    First of all you need to provide radio button in place of checkboxes because an user can be either admin or student/lecturer so change this to radio button and don't make any array just simply fetch values and jion them by AND condition in query

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分