duankuai6586 2015-08-24 18:17
浏览 17

具有多个数据库的登录页面

I have a website that I need users to be able to login to. It is currently on a different server from the company's actual website. I would like to have a single login form that checks for a username and password in multiple databases on the same server.

Heres the setup.

1 Database has 2 different tables that I need to check for username and password. the other database has 1 table that I need to check.

I will have a checkbox for 1 of the tables in the first database. So the form will have 3 field. (Username, Password, and "I am a reporter" checkbox)

I believe that it has something to do with the UNION sql command.

I don't know a LOT about sql but I am trying to learn as I go...

Here is the code so far.. also, I hope someone will tell me whether the information will be passed securely or not.

<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
    if (empty($_POST['uname']) || empty($_POST['pswd'])) {
        $error = "Username or Password is invalid";
    }
    else
    {
        // Define $username and $password
        $uname=$_POST['uname'];
        $pswd=$_POST['pswd'];
        // Establishing Connection with Server by passing server_name, user_id and password as a parameter
        $con = mysql_connect("10.0.0.3", "webaccess", "ccrweb");
        // To protect MySQL injection for Security purpose
        $username = stripslashes($username);
        $password = stripslashes($password);
        $username = mysql_real_escape_string($username);
        $password = mysql_real_escape_string($password);
        // Selecting Database
        $db = mysql_select_db("company", $connection);
        // SQL query to fetch information of registerd users and finds user match.

        $query = mysql_query("select * from dbo.contacts where WebPwd='$password' AND WebAcctName='$username'", $connection);

        $rows = mysql_num_rows($query);

        if ($rows == 1) {
            $_SESSION['login_user']=$username; // Initializing Session
            header("location: "); // Redirecting To Other Page
        } else {
            $error = "Username or Password is invalid";
        }
        mysql_close($connection); // Closing Connection
    }
}
?>

It is not all complete yet and I am still researching but I am also trying to do this as quick as possible.

any help will be greatly appreciated!

  • 写回答

2条回答 默认 最新

  • dongzaijiao4863 2015-08-24 18:21
    关注

    It appears you make a connection declaring one name and then a different connection object name later.

    $con = mysql_connect("10.0.0.3", "webaccess", "ccrweb");
    
    $db = mysql_select_db("company", $connection);
    

    I believe the later should use the same name $con and also at the end mysql_close($con);

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化