0

我是 PHP 新手。我用用户 A 和 pw 123(测试)创建了一个 microsoft access 数据库。我试图在网站上找到,但不幸的是我找不到任何可以真正引导我对 MS Access 进行身份验证的网站,大部分网站都是关于 SQL 的,这是我真正不想要的,请帮助!

目前这里是我的代码

登录.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>  

数据库.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

1 回答 1

1
    session_start();

    // 获取从用户那里收集的数据
    $用户名 =$_POST["用户名"];
    $Password =$_POST["密码"];

    if (!$conn = new COM("ADODB.Connection"))
    exit("无法创建 ADODB 连接
"); $strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". 真实路径(“数据库文件”); $conn->open($strConn); $strSQL = "SELECT username, password FROM accounts WHERE username = '$Username' AND password = '$Password'"; $rs = $conn->执行($strSQL); 如果 (!$rs->EOF) { if ( $rs->Fields["用户名"]->值 && $rs->Fields["Username"]->value == $Username && $rs->字段[“密码”]->值 && $rs->Fields["Password"]->value == $Password ) { $_SESSION["authenticatedUser"] = $用户名; // 重定位到登录页面 header("位置:login.php"); } } 别的 { $_SESSION["message"] = "$Username 登录错误。" ; header("位置:admin.php"); }
于 2012-04-10T07:25:23.673 回答