Jump to content

Recommended Posts

Okay I have a stupid question here.. I have a form where users enter in information. One of the fields is an employee ID field. I need to verify that they enter in a valid Employee ID. The form is in an external html file so here is my php submit form.

<?php

require("config.php");

if($_GET['action'] == 'post')
{
   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
  echo 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";
      }
}   
?>

 

All of the employee ID's are located in a table called analyzer_query. I think i have the code right to do this but here it is

   $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = ($_POST['Employee_ID'])") or die("Please enter correct EmployeeID");

 

My question is, is this correct? and where should i put it? ???

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/74749-php-ms-access-form-question/
Share on other sites

something like this

 

depends on the connection type

<?php

require("config.php");

if($_GET['action'] == 'post')
{
   if(!empty($_POST['Employee_ID']))
    {
        $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}") or die("Please enter correct EmployeeID");
//unsure if your using ODBC
if ($db_conn->odbc_num_rows < 1){
  error("blank");
  exit;
}
    }

   if( 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";
      }
}   
?>

also

echo error("blank");

should be

error("blank");

 

 

yeah guess it would've helped if i had posted this with it...

 

<?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); 
?>

Okay.. i haven't used ADODB, for a while but i think this should do it..

<?php

require("config.php");

if($_GET['action'] == 'post')
{
   if(!empty($_POST['Employee_ID']))
    {
        $ret = $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}") or die("Please enter correct EmployeeID");

        if ($ret->FieldCount() < 1)
        {
    error("blank");
    exit;
        }
    }

   if( 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";
      }
}   
?>

ok i used that..and got this


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 10


Please enter correct EmployeeID

 

edit -

 

guess i should have added thats what i got when i tested it with an invalid id

change

        $ret = $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}") or die("Please enter correct EmployeeID");

to

var_dump($_POST['Employee_ID']);
        $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}";
        $ret = $db_conn->Execute($Query) or die("Please enter correct EmployeeID:$Query");

string(3) "das"

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

Please enter correct Employee ID

 

???

 

thats all of the error it gives me

<?php

require("config.php");

if($_GET['action'] == 'post')
{
  if(!empty($_POST['Employee_ID']))
    {
        var_dump($_POST['Employee_ID']);
        $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}";
        $ret = $db_conn->Execute($Query) or die("Please enter correct EmployeeID:$Query");
        if ($ret->FieldCount() < 1)
        {
    error("blank");
    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";
      }
}   
?>

and this is the error i get

string(9) "bcourtney" 
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 11
Please enter correct EmployeeID:SELECT * FROM analyzer_query WHERE Employee_ID = bcourtney

$Query = "SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}";

should be

$Query = "SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'";

Note the single quotes

SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'";

<?php

require("config.php");

if($_GET['action'] == 'post')
{
  if(!empty($_POST['Employee_ID']))
    {
        var_dump($_POST['Employee_ID']);
        $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'";
        $ret = $db_conn->Execute($Query) or die("Please enter correct EmployeeID:$Query");
        if ($ret->FieldCount() < 1)
        {
    error("blank");
    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";
      }
}   
?>

 

still get the same error with this code.

Ok I tried that and got this


Warning: (null)(): Unable to lookup fieldcount: Unknown name. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 12

 

Well i know how to do it with mysql

$result = mysql_query("SELECT * FROM users_table
        WHERE username='{$_POST['username']}'") or die(mysql_error());
        $row = mysql_fetch_array( $result );

 

or maybe i'm not doing something right...or i'm not on the right track..

  • 2 weeks later...

Okay so i really cannot figure this out and i need help if someone can help me. I need to have the employee id be validated (make sure it's in the login database) before the data from the form is put into the database if this makes any sense. here is the code for the form

 

<?php
require("config.php");
if($_GET['action'] == 'post')
{
   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";
      }
}
?>

 

here is the config.php file

<?php
$db_conn = new COM("ADODB.Connection");
$connstr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=F:\Wellness Program\Copy of HR Employee Wellness Program.mdb;";
$db_conn->open($connstr);
?>

 

Can someone help me? Point me in the direction of a tutorial or how to go about doing this. i've tried all of the above code's and haven't had any luck.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.