PhP Log In with Access DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmilton262
    New Member
    • Nov 2013
    • 1

    PhP Log In with Access DB

    I am trying to log in using php and an Access db but it does not seem to be working, please help.

    I have login.php, the user enters the username and password stored in the access db, php does some validation through php, connects to the database and logs in the user if the username and password are correct.

    The column names in my Access db are called 'username' and 'password'.

    This is my code:

    Code:
    <?php 
    
    $User = $_REQUEST['username'];
    $Password = $_REQUEST['password'];
    $adoCon = new COM("ADODB.Connection");
    $sHere = dirname(__FILE__);
    
    Try
    {
     	$adoCon->Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=$sHere/ses.accdb");
    }
    catch(Exception $e)
    {
    	die('Sorry - Error.<br />' . "[$sHere]<br />$e");
    }
    
    $query = "SELECT * FROM tblStudent WHERE username = '$User' AND password = '$Password'";
    $rsMain = $adoCon->Execute($query);
    
    if (!$rsMain->EOF)
    {
    	{
    	$dbUser = $rsMain->Fields("username")->value;
    	$dbUserPassword = $rsMain->Fields("password")->value;
    
    	}
    if ($User==$dbUser&&$UserPassword==$dbUserPassword)
        {
      		echo "Logged In <a href='index.php?p=profile'>Enter Home<a/>";
    		$_SESSION['username'] = $dbUser;
        }
      else
    
      		echo "Sorry! <a href='index.php?p=login'>Retry:</a>";
    }
      else
      
      		echo ("Sorry! <a href='index.php?p=login'>Retry:</a>");
     
    $rsMain->Close();
    $rsMain = null;
    
    $adoCon->Close();
    $adoCon = null;
    
    ?>
    Last edited by Dormilich; Nov 28 '13, 08:01 PM. Reason: please use [code] [/code] tags when posting code
Working...