在客户端表或代理表上选择,并从所选表中获取所选字段的值

时间:2016-11-30 11:47:31

标签: php mysql

我有一个登录页面,用于从用户名和密码字段中选择Client表中的数据。但我也有一个代理人表,其中也包含用户名和密码字段。

现在我想从代理或客户端表中进行选择,当选择其中一个时,也可以获取其他字段数据

<?php 
include 'database/connect.php';

if (isset($_POST['login'])) {

    $user = htmlspecialchars($_POST['username']);
    $pass = $_POST['password'];
    $user = mysqli_escape_string($conn,$user);

    $sql = "SELECT * FROM clients WHERE username='$user' AND password='$pass'";
    $result = $conn->query($sql);

    if (empty($user) || empty($pass)) {

        echo "<div class='warn' align='left'><embed src='icons/x-01.png'><div class='txt'>You haven't entered any input!</div></div>";

    } else {

        if (!$row = $result->fetch_assoc()) {

                echo "<div class='warn' align='left'><embed src='icons/x-01.png'><div class='txt'>Invalid Username or Password!</div></div>";
        } else {

            $fullname = $row['firstname'] . " " .$row['middlename']. " " . $row['lastname'];
            $_SESSION['name'] = $fullname;
            $_SESSION['username'] = $user;
            echo "<script>window.open('myaccount.php','_self')</script>";
        }
    }
}
?>

0 个答案:

没有答案