Jump to content

PHP + MS Access Submit form errors


bCourtney07

Recommended Posts

Yeah it's me again. here's my code

 

<?php
ob_start();
//include the header.php file 
require("config.php");
echo "<title>Human Resources Employee Wellness Program</title>";
//Displays form
echo "<form method=post action=wellness.php?action=check>
<table align=center width=75% cellpadding=5 cellspacing=5>
    
     <tr>
           <td>Employee ID:</td>
           <td><input type=text name=Employee_ID></td>
       </tr>
       <tr>
           <td>Date:</td>
           <td><input type=text name=Date></td>
       </tr>
       <tr>
           <td>Activity:</td>
           <td>
               <select name=Activity>
                       <option value=Aerobics>Aerobics</option>
                       <option value=BackpackingHicking>Backpacking/Hicking</option>
                       <option value=Basketball>Basketball</option>
               </select>
           </td>
       </tr>
       <tr>
           <td>Miles:</td>
           <td><input type=text name=Miles></td>
       </tr>
        <tr>
           <td colspan=2 align=center><input type=submit value=Submit><input type=reset value=Reset></td>
       </tr>
</table>
</form>";

if($_GET['action'] == 'check')
{
   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
         {
      $row = $db_conn->GetArray("SELECT * FROM analyer_query WHERE Employee_ID='{$_POST['Employee_ID']}'") or die("Error in verifying Employee ID");
         if($row >= 0)
   {
      $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");
           }
 else
    {
	echo error("user");
		}
}
}
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);
?>

 

here is the error i'm getting when it loads

Notice: Undefined index: action in F:\InetPub\wwwroot\EmployeeWellnessProgram\wellness.php on line 44

 

here is line 44

if($_GET['action'] == 'check')

 

here are the errors i'm getting when i try to submit the form

Warning: (null)(): Invoke() failed: Exception occurred. Source: ADODB.Connection Description: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. in F:\InetPub\wwwroot\EmployeeWellnessProgram\wellness.php on line 54
Error in verifying Employee ID

 

What i'm trying to do is verify that the Employee ID is correct and in the analyzer_query table. Can someone please help me?  ???

Link to comment
Share on other sites

This what I would try first, to me it just makes it easier to read and follow.

 

Take all that HTML at the top and remove it from the PHP tags.  There is no reason to echo all that.

 

Make your PHP Code up top and your HTML form after your PHP Code (in HTML and not inside PHP).

Link to comment
Share on other sites

The second error is telling you that you have this section wrong.

 

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

 

Make sure your syntax for these lines are correct.

Link to comment
Share on other sites

Sorry, forgot to do this.


<title>Wellness Program</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function sendFocus() {
	document.forms[0].Employee_ID.focus();
	}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body onload="sendFocus()">
<form action="wellness.php?action=check" method="post">
<table align="center" width="75%" cellpadding="5" cellspacing="5">
       <tr>
           <td rowspan="8">
           <!-- IMAGE -->
           <img src="HeadToToeHealthcare.bmp" width="210" height="346"></td>
       </tr>
       <tr> <!-- TITLE ON TOP OF PAGE -->
           <th colspan="2">Human Resources Employee Wellness Program - Enter Mileage Form</th>
       </tr>
    <tr> <!-- Employee ID Field -->
          <td>Employee ID:</td>
          <td><input type="text" name="Employee_ID"></td>
      </tr>
      <tr> <!-- DATE Field -->
          <td>Date:</td>
          <td><input type="text" name="Date" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" onKeyDown="if(event.keyCode==13) event.keyCode=9;"></td>
      </tr>
      <tr> <!-- Activities -->
          <td>Activity:</td>
          <td>
              <select name="Activity">
                      <option value="Aerobics">Aerobics</option>
                      <option value="BackpackingHicking">Backpacking/Hicking</option>
                      <option value="Basketball">Basketball</option>
                      <option value="BikeRiding">Bike Riding</option>
                      <option value="Bowling">Bowling</option>
                      <option value="DanceClasses">Dance Classes</option>
                      <option value="ExerciseClass">Exercise Class</option>
                      <option value="Football">Football</option>
                      <option value="Golfing">Golfing</option>
                      <option value="IceSkating">Ice Skating</option>
                      <option value="MountainClimbing">Mountain Climbing</option>
                      <option value="Other">Other</option>
                      <option value="Racquetball">Racquetball</option>
                      <option value="RollerBladingRollerSkating">Roller Blading/Roller Skating</option>
                      <option value="Rowing">Rowing</option>
                      <option value="Shuffleboard">Shuffleboard</option>
                      <option value="Softball">Softball</option>
                      <option value="Swimming">Swimming</option>
                      <option value="TaiChi">Tai Chi</option>
                      <option value="Tennis">Tennis</option>
                      <option value="Volleyball">Volleyball</option>
                      <option value="WalkingRunningJogging">Walking/Running/Jogging</option>
                      <option value="Yoga">Yoga</option>
              </select>
          </td>
      </tr>
      <tr> <!-- Miles -->
          <td>Miles:</td>
          <td><input type="text" name="Miles" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" onKeyDown="if(event.keyCode==13) event.keyCode=9;"></td>
      </tr>

      <tr>
          <td colspan="2" align="center"><input type=submit value=Submit>
            <input type=reset value=Reset></td>
      </tr>
</table>
</form>

<?php
ob_start();

require("config.php");

if($_GET['action'] == 'check')
{
  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
        {
     $row = $db_conn->GetRow("SELECT * FROM analyer_query WHERE Employee_ID='{$_POST['Employee_ID']}'") or die("Error in verifying Employee ID");
        if($row != '')
   {
     $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");
          }
 else
    {
	echo error("user");
		}
}
}
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";
     }
}
?>

 

Well config file worked before i tried adding this verifying crap. it entered the information into the database fine until now.

 

this is line number 88

  
$row = $db_conn->GetRow("SELECT * FROM analyer_query WHERE Employee_ID='{$_POST['Employee_ID']}'") or die("Error in verifying Employee ID");

Link to comment
Share on other sites

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.