Page 1 of 1

PHP Login script with ODBC Microsoft Access

Posted: Mon Jan 17, 2005 2:33 am
by Pointeo13
Hi, I was wondering if anyone knew how to make a login in script (username/password) that can connect to a ODBC Microsoft Access Database. I just need the code to checked the Microsoft Access Database to see if the user has enterd the name and password correctly if they dont it rejects them. I would use MySQL but the guy does not want it, he just wants to stick with Microsoft Access. So can somone please help me out I have been looking all over. I dont even need the login page just the connection to check if the users are in the database. I have written scripts to show you what tables are there and add to them if somone wants to registar just need to touch it and say yes user is accepted. Thank you so much.

P.S. - If anyone needs a login script for MySql I can write one in 5min just let me know or any other scripts, I will help all I can since I am a newbie on this site.

Posted: Mon Jan 17, 2005 2:37 am
by feyd

Posted: Mon Jan 17, 2005 2:45 am
by Pointeo13
Thanks for the help, but the first link just shows how to fetch it, I can fetch my data np. I need to have it check to see if the user is granted access not fetch the data. But thanks majorly and such a fast reply.

Posted: Mon Jan 17, 2005 3:12 am
by feyd
:oops: it looked promising when I ran through it :mrgreen: sorry.

Posted: Mon Jan 17, 2005 8:46 am
by fangorn
If you can fetch tables, then you already have an odbc_connect(), right?
See this page in the manual and scoll down, the very first User Contributed Notes answers your question.

http://us3.php.net/manual/en/function.odbc-connect.php

You need to use odbc_exec(),odbc_fetch_row(), and odbc_result(), in that order.

Posted: Mon Jan 17, 2005 2:44 pm
by Pointeo13
Ok this is what I have so far, all I can get it to do is to display the code, could somone help me how to make it just check the result and if the persons first name and last name is in the database then redirect them to a page. Just pretend that first name and last name is User name and Password. I was just using this as a test purpose later I will change the database names.

Code: Select all

<?php

function HTML_Head() &#123;
    echo "
    <HTML><HEAD>
    <TITLE>Processing Form</TITLE>
    </HEAD>
    <BODY BGCOLOR="#D5D5AB">";
&#125;

function HTML_Foot() &#123;
    echo "</body></html>";
&#125;

function Database_Entries($msg) &#123;
    echo $msg;
&#125;

function Output_Entries() &#123;
   

    $cnx = odbc_connect( 'WebTute' , 'root', '' );
    if (!$cnx) &#123;
        Error_handler( "Error in odbc_connect" , $cnx );
    &#125;

    $cur= odbc_exec( $cnx, "select FirstName,LastName from Inputform" );
    if (!$cur) &#123;
        Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
    &#125;
    echo "<table border=1>
	<tr>
		<th>First Name</th>
		<th>Last Name</th>
		
	</tr>\n";
    $nbrow=0;   

  
    while( odbc_fetch_row( $cur ) ) &#123;
        $nbrow++;
        
		$FirstName= odbc_result( $cur, 1 ); // get the field "FirstName"
        $LastName= odbc_result( $cur, 2 ); // get the field "LastName"

        echo "
		<tr>
			
			<td>$FirstName</td>
			<td>$LastName</td>
			</tr>\n";
    &#125;

    echo "<tr><td colspan=2>$nbrow entries </td></tr></table>";

   
    odbc_close( $cnx);
&#125;

function Error_Handler( $msg, $cnx ) &#123;
    echo "$msg \n";
    odbc_close( $cnx);
    exit();
&#125;

?>
I have more code for it, but that just has it add the names in from the first page when they enter in there First name and last name. Well thanks again.

Posted: Fri Jan 21, 2005 8:25 am
by fangorn
What do you mean "display the code"? Are you saying that when you open a browser and run a .php file, your browser just shows you the text that you put in the file?