Does anyone have a place where I can find a relatively simple tutorial on how to do a PHP Login system for a website using MSAccess

I realize that many of you may frown at Access as MQL seems to be the crowd favourite for obvious reasons, but Access is what the format must be in.

Im 90% Php retarded, but I need to get this done.

I have some code that is pretty ugly and..well doesnt work..

so I was looking for a tutorial on this..and google isnt being kind.

    I guess I should be more specific

    I have a MsAccess database with user names and logins

    Currently I have a login system that is crap, so I wanted to instead do a PHP-based login.

    I need to use the existing MsAccess Data

    so what I will have (I think)

    A.) a user login page
    w/ $USerName $User Pass fields

    B.) a php page that
    takes the data from the login form and makes it usueable
    open database
    checks specified database field for record that matches

    username
    checks same record to see if pass matches
    if match - starts session/cookie/whatever
    if no match return to login page - display error msg
    *close db

    C.) A code snippet that I can place in page headers to check to
    see if the person viewing the page is logged in.

      Dunno if this will help but I use a free convertor from bullzip to convert from MS Access to sql then upload it to the mysql database.

        Thanks Thats pretty neat. I'll keep that as a future ref.

        but this project cannot use anything other than access for the database.

        🙁

          <?php

          session_start();

          $UserName=$POST ['UserName'];
          $UserPass1=$
          POST ['UserPass1'];

          $cnx = odbc_connect( 'dbName' , 'AdminName', 'password' );
          $query = "SELECT UserName, UserPass1 FROM WebUser";
          $result = odbc_exec($connect, $query);
          while(odbc_fetch_row($result)){
          $UserName = odbc_result($result, 1);
          $UserPAss1 = odbc_result($result, 2);
          print("$UserName $UserPass1\n");
          }

          if ($_POST['Submitted'] == "True") {

          if ($_POST['UserName'] == $_Username && $_POST['UserPass1'] == $_Password) { 
              $_SESSION['Logged_In'] = "True"; 
              $_SESSION['UserName'] = $_Username; 
          } 

          }

          if ($_SESSION['Logged_In'] != "True") {

          echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\"> 
              Username: <input type=\"textbox\" name=\"UserName\"><br /> 
              Password: <input type=\"textbox\" name=\"UserPass1\"><br /> 
              <input type=\"hidden\" name=\"Submitted\" value=\"True\"> 
              <input type=\"Submit\" name=\"Submit\"> 
          </form>"; 

          }
          else
          {
          echo "You are logged in as: <b>" . $SESSION['Username'] . "</b>
          <br /><a href=\"" . $
          SERVER['PHP_SELF'] . "?mode=logout\">Logout</a>";
          }

          if ($GET['mode'] == "logout") {
          session_start();
          $
          SESSION = array();
          session_destroy();

          echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=" . $_SERVER['PHP_SELF'] . "\">"; 

          }

          odbc_close($connect);

          ?>

            this is what i have now...

            still isnt working 🙁

            <?php
            session_start();

            $UserName=$POST ['UserName'];
            $UserPass1=$POST ['UserPass1'];

            if ($POST['Submitted'] == "True") { if ($POST['Username'] == $Username && $POST['Password'] == $Password) { $SESSION['Logged_In'] = "True"; $SESSION['Username'] = $Username; } }

            if ($SESSION['Logged_In'] != "True") { echo "<form method=\"post\" action=\"" . $SERVER['PHP_SELF'] . "\"> Username: <input type=\"textbox\" name=\"Username\"><br /> Password: <input type=\"textbox\" name=\"Password\"><br /> <input type=\"hidden\" name=\"Submitted\" value=\"True\"> <input type=\"Submit\" name=\"Submit\"> </form>"; }
            else {echo "You are logged in as: <b>" . $SESSION['Username'] . "</b> <br /><a href=\"" . $SERVER['PHP_SELF'] . "?mode=logout\">Logout</a>";}

            if ($GET['mode'] == "logout") { session_start(); $SESSION = array(); session_destroy(); echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=" . $_SERVER['PHP_SELF'] . "\">"; }

            function HTML_Head() {echo "<HTML><HEAD><TITLE>Processing Form</TITLE></HEAD><BODY>"; }
            function HTML_Foot() {echo "</body></html>";}
            function Database_Entries($msg) {echo $msg;}

            function Output_Entries() {
            $cnx = odbc_connect( 'None' , 'Never', 'hey' );
            if (!$cnx) {Error_handler( "Error in odbc_connect" , $cnx );}

            $cur= odbc_exec( $cnx, "select UserPass1 from WebUser where UserName='$UserName'");
            if (!$cur) {Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );}
            $nbrow=0;  
            while( odbc_fetch_row( $cur ) ) {
                $UserName= odbc_result( $cur, 2 ); // get the field ""
                $UserPass1= odbc_result( $cur, 3 ); // get the field ""
            }
            
            echo "<tr><td colspan=2>$nbrow entries </td></tr></table>";
            odbc_close( $cnx);

            }

            function Error_Handler( $msg, $cnx ) { echo "$msg \n"; odbc_close( $cnx); exit(); }

            $strOldEntries = "Previous Entries in database";

            HTML_Head();
            Database_Entries($strOldEntries);
            Output_Entries();
            HTML_Foot();

            ?>

              okay since i can connect to the obdc connection and get results

              can anyone explain how to use those results to work as a lusername?

              i think im missing a step somewhere.

                honestly.. i can hardly read that code. you need to indent it, put it in php tags so we get syntax highlighting, and get rid of all those one liners!! :-p

                well, if your comforatble with the one liners... up to you.

                anyway. i can see right near the top you are checking if the form has been posted

                if ($_POST['Submitted'] == "True") // ps: this could be changed too if ($_POST['Submitted'])
                

                then you are trying to set some session variables with variables that have no values.

                if ($_POST['Username'] == $_Username
                

                $_Username is empty. why? because it doesnt get a value until much later in the script.

                you need to.

                get the user to fill in the form
                post it to a script which checks the user exists
                if they do exist, set valid session vars.
                else redirect them back to login.

                  get the user to fill in the form
                  post it to a script which checks the user exists
                  if they do exist, set valid session vars.
                  else redirect them back to login.

                  ..thats what I thought I was doing.
                  so, none of this code works?

                  do you know of a tutorial somehwere that can help me with the php, mcasses. obdc connection login?

                    Write a Reply...