Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2007
    Posts
    27

    Unanswered: PHP + Access Error: Warning: (null)(): Invoke() failed: Exception occurred.

    Okay so here is my source code that submits the form to the database

    Code:
    <?php
    
    require("config.php");
    
    if($_GET['action'] == 'post')
    {
      if($_POST['Employee_ID'] != '')
        {
             $ret = $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}") or die("Error validating Employee ID");
            $itemfields = Count("Employee_ID");
          
            if ($itemfields <= 1)
            {
    	    error("user");
    	    exit;
            }
        }
       if(empty($_POST['Employee_ID']) || empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles']))
        {
          //if everything is not filled in than prints out error message
    	  error("blank");
    	  exit;
          }
    else 
    
       $db_conn->Execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')") or die("Error in connecting to the database");
    header("Location: success.php?action=success");
    }
    function error($error)
    {
       //if error is equal to blank
       if($error == 'blank')
          {
          echo "Please fill in all the required fields before submitting";
          }
     //if error is equal to blank
       if($error == 'user')
          {
          echo "Please fill in the correct Employee ID";
          }
    }
    ?>
    with the config file
    Code:
    <?php
    $db_conn = new COM("ADODB.Connection");
    $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./Copy of HR Employee Wellness Program.mdb").";";
    $db_conn->open($connstr); 
    ?>

    and now here is the error i'm getting

    Code:
    Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query expression 'Employee_ID = 'ff'. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 9
    Error validating Employee ID
    Can anyone help me because i'm absolutely clueless. ???

  2. #2
    Join Date
    Jan 2005
    Posts
    362
    Code:
     $ret = $db_conn->
    Execute("SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}") 
    or die("Error validating Employee ID");
    I see a " ' " more at
    Code:
     '{$_POST['Employee_ID']}")
    ,
    are you sure it have to be there??
    Look for errors like that.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    microsoft access does not recognize mysql's proprietary `backticks`

    also, access is much more rigorous about when you are allowed to quote numeric literals -- i.e. never

    this might be allowed in mysql --

    ... where Employee_ID = '937'

    but in access you would have to say --

    ... where Employee_ID = 937

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Oct 2007
    Posts
    27
    well how do i do the check when i'm getting the information from the form?

    Employee_ID = {$_POST['Employee_ID']} ?? or what?

    Well tried that and got this
    Code:
    Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 9
    Error validating Employee ID
    again

  5. #5
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Quote Originally Posted by mstng07
    well how do i do the check when i'm getting the information from the form?

    Employee_ID = {$_POST['Employee_ID']} ?? or what?

    Well tried that and got this
    Code:
    Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 9
    Error validating Employee ID
    again
    Why not fix your connection issue before you start on form validation..

    dimis2500 is correct, you have one too many single quotes in this string:

    Code:
     $ret = $db_conn->
    Execute("SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}") 
    or die("Error validating Employee ID");
    Put another single quote after the closing curly bracket in the Employee_ID var. (See post# 2 for details)

  6. #6
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Still using the COM object eh... My advice, ditch that and use odbc. You'll rue the day that the COM object changes
    You probably want some reasoning to my madness :
    The COM object is NOT part of PHP and thus you relying on an external object to perform your functions. PHP is only acting as an intepreter here. Therefore, any changes to your COM object will not be changes to PHP, so you may find one day that it stops working or performs irregularly. Also bear in mind that PHP may alter the way that it works with COM objects. You have two points of failure here. If you use PHP only you are ruling out one of those...

  7. #7
    Join Date
    Oct 2007
    Posts
    27
    Yeah well I'd switch if I weren't in so deep already so to speak. I got everything working now except where it checks to see if the user is in the database or not. I'm going to try to eliminate the errors i'm getting with it and just do a login page.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •