2012-04-10 3 views
0

PHP를 처음 사용합니다. 나는 사용자 A와 pw 123 (테스트)을 사용하여 Microsoft Access 데이터베이스를 만들었습니다. 나는 웹 사이트에서 찾으려고했지만 불행히도 MS Access에 대해 실제로 나를 인증 할 수있는 것을 찾을 수 없다. 대부분의 웹 사이트는 순전히 SQL에 관한 것이고, 나는 정말로 원하지 않는 것이다.Microsoft Access에 대한 간단한 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); 
?> 

은 내가 어떻게 여기에서 계속 않습니다

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입니까? 고맙습니다! MS Access 2003에서만 모든 것을 인증 할 수 있습니다.

+4

데이터베이스에 MS Access를 사용하지 마십시오. : ( – Amber

+0

안녕하세요 Amber, 저는 선택의 여지가 없습니다. Superior가 사용하도록 요청했습니다. (어쨌든이 웹 사이트를 통해 여기저기서 답변을 조정하면 간단한 로그인 도움을 얻을 수 있습니다! http://bytes.com/topic/php/대답/794640-simple-login-using-ms-access-odbc – Newbie

+0

쿼리가 실행되거나 오류가 발생합니까? 사용자 이름과 암호가있는 Users 테이블이 있습니까? 정확히 어디에 집착합니까? – Yaniro

답변

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"); }