如何添加不同类型的帐户?

时间:2018-02-01 04:41:14

标签: php mysql

你好这个php的新手就像问我如何在我的注册文件中添加不同的帐户类型,其中admin = 1 customer = 2 employee = 3我不知道如何实现我的代码。

我的注册表单

<?php
    include('conn.php');
    if(isset($_POST['susername'])){
        $username=$_POST['susername'];
        $password=$_POST['spassword'];

        $query=$conn->query("select * from user where username='$username'");

        if ($query->num_rows>0){
            ?>
                <span>Username already exist.</span>
            <?php 
        }

        elseif (!preg_match("/^[a-zA-Z0-9_]*$/",$username)){
            ?>
                <span style="font-size:11px;">Invalid username. Space & Special Characters not allowed.</span>
            <?php 
        }
        elseif (!preg_match("/^[a-zA-Z0-9_]*$/",$password)){
            ?>
                <span style="font-size:11px;">Invalid password. Space & Special Characters not allowed.</span>
            <?php 
        }
        else{
            $mpassword=md5($password);
            $conn->query("insert into user (username, password) values ('$username', '$mpassword')");
            ?>
                <span>Sign up Successful.</span>
            <?php 
        }
    }
?>

这里是我创建多用户角色的文件的login.php

<?php 
    include('conn.php');
    session_start();
    if(isset($_POST['username'])){
        $username=$_POST['username'];
        $password=md5($_POST['password']);

        $query=$conn->query("select * from users where username='$username' and password='$password'");

        if ($query->num_rows>0){
            $row=$query->fetch_array();
            $_SESSION['users']=$row['id']; 
        }
        else{
            ?>
                <span>Login Failed. User not Found.</span>
            <?php 
        }
    }
?> 
how do i add them in my code.

0 个答案:

没有答案