We are trying to build a login system for a PHP CMS. At the moment, there is one record in an Access database called ‘Administrator’ which contains one user record with AutoNumber ID ‘1’, username ‘admin’ and password ‘password’. When testing the login page using this username and password, we always get the ‘Wrong Username and Password’ error and we aren’t sure why. We believe the problem is in the variables.
[php]<?php
session_start();
require ‘DBConn.php’;
$db=@odbc_connect($dbconn,’’,’’)
or die("connect error: ".odbc_error());
// get passed parameters
$username=trim(stripslashes($_POST[‘username’]));
$password=trim(stripslashes($_POST[‘password’]));
$sql=“SELECT * FROM Administrator WHERE username=’$username’ and password=’$password’”;
// prepare and execute in 1 statement
$result=odbc_exec($db,$sql)
or die ("result error ".odbc_error().’-’.odbc_errormsg());
// if no result: no rows read
if (!odbc_fetch_row($result)) {
die(“Wrong Username or Password”);
// else: all is okay
} else {
$_SESSION[‘username’]=$username;
$_SESSION[‘password’]=$password;
header(“location:login_success.php”);
}
odbc_close($db);
?>[/php]