2012-04-10 54 views
0

我是PHP新手。我用用戶A和123(測試)創建了一個微軟訪問數據庫。我試圖在網站上找到,但不幸的是我找不到任何實際上可能導致我對MS Access進行身份驗證的任何事情,大部分網站純粹是關於SQL,這是我真正不想要的,請幫助!簡單的登錄與Microsoft Access的PHP檢查

目前這裏是我的代碼

的login.php

<html> 
<body> 
<?php 
session_start(); 
// dBase file 
include "database.php"; 

<form id='login' action='login.php' method='post' accept-charset='UTF-8'> 
<fieldset > 
<legend>Please log in your employee ID and Password to apply for leave.</legend> 
<input type='hidden' name='submitted' id='submitted' value='1'/> 
<div class='short_explanation'>* required fields</div> 
<br> 
<label for='username'>UserName*:</label> 
<input type='text' name='username' id='username' maxlength="50" /> 
<br> 
<label for='password'>Password*:&nbsp;</label> 
<input type='password' name='password' id='password' maxlength="50" /> 
<br><br> 
<input type='submit' name='Submit' value='Submit' /> 
</fieldset> 

database.php中

<?php 
// This part sets up the connection to the 
// database (so you don't need to reopen the connection 
// again on the same page). 
$conn=odbc_connect("employee","","") or die (odbc_errormsg()); 
if (!$conn) 
{ 
exit 
("Error connecting to database: ".$conn); 
} 
// Then you need to make sure the database you want 
// is selected. 
$sql = "SELECT * FROM empTable"; 
$rs=odbc_exec($conn,$sql); 
?> 

如何從這裏繼續下去嗎?謝謝!請注意,我只能使用MS Access 2003驗證所有內容。

+4

請不要將MS Access用於您的數據庫。 :( – Amber 2012-04-10 06:34:08

+0

嗨琥珀,我沒有選擇,高級要求我使用它:(無論如何,我通過簡單的登錄通過調整這裏和那裏通過這個網站的答案!http://bytes.com/topic/php/answers/794640-simple-login-using-ms-access-odbc – Newbie 2012-04-10 06:46:27

+0

你的查詢是否執行或你得到錯誤?你有一個用戶名和密碼的用戶表?你究竟在哪裏卡住? – Yaniro 2012-04-10 06:56:36

回答

1
 
    session_start(); 

    // Get the data collected from the user 
    $Username =$_POST["username"]; 
    $Password =$_POST["password"]; 

    if (!$conn = new COM("ADODB.Connection")) 
    exit("Unable to create an ADODB connection
"); $strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("DATABASEFILE"); $conn->open($strConn); $strSQL = "SELECT username, password FROM accounts WHERE username = '$Username' AND password = '$Password'"; $rs = $conn->execute($strSQL); if (!$rs->EOF) { if ($rs->Fields["Username"]->value && $rs->Fields["Username"]->value == $Username && $rs->Fields["Password"]->value && $rs->Fields["Password"]->value == $Password ) { $_SESSION["authenticatedUser"] = $Username; // Relocate to the logged-in page header("Location: loggedon.php"); } } else { $_SESSION["message"] = "Login Error as $Username. " ; header("Location: admin.php"); }