Jump to content

[SOLVED] PHP error: Notice: Undefined index


bCourtney07

Recommended Posts

I can't figure out what i'm doing wrong. I have a form that is supposed to post information to an access database (yeah not my choice to create it in access) here are the files i have:

The form:

<html>
<head>
<title>Wellness Program</title>
</head> 
<body> 
<form action="WellnessSubmit.php" method="post">
<table>
       <tr>
           <td>Employee ID:</td>
           <td><input type="text" name="employeeid"></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>
                       <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>
           <td>Miles:</td>
           <td><input type="text" name="miles"></td>
       </tr>
       <tr>
           <td><input type=submit value=Submit></td>
           <td><input type=reset value=Reset></td>
       </tr>
</table>
</form>

 

The WellnessSubmit.php file:

<?php

require("config.php");

if($_GET['action'] == 'post')
{
   if($_POST['employeeid'] == '' || $_POST['date'] == '' || $_POST['activity'] == ''  || $_POST['miles'] == '')
    {
      //if everything is not filled in than prints out error message
  echo error("blank");
  exit;
   }

     $conn->Execute("INSERT INTO Activity_Log
                  ('Employee_ID', 'Date', 'Activity', 'Miles') VALUES('$_employeeid', '$_date', '$_activity', '$_miles') ")
            or die(ADODB_error());
                  }


function error($error)
{
   //if error is equal to blank
   if($error == 'blank')
      {
      echo "<b>Please fill in all the required fields before submitting</b>";
      }
}   
?>

 

the config.php file:

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

 

Now. Here is the error i'm getting ???

Notice: Undefined index: action in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 7

 

Any help in figuring this out would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/74641-solved-php-error-notice-undefined-index/
Share on other sites

Okay that fixed that error! Thank you soo so much!

 

Now i've got this one

Fatal error: Call to a member function on a non-object in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 14

 

???

 

this is just frustrating

well i noticed and changed that right after i posted. but now....i have a bunch more  :(

Notice: Undefined variable: _Employee_ID in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 16

Notice: Undefined variable: _Date in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 16

Notice: Undefined variable: _Activity in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 16

Notice: Undefined variable: _Miles in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 16

Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] The INSERT INTO statement contains the following unknown field name: ''Employee_ID''. Make sure you have typed the name correctly, and try the operation again. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 16

Fatal error: Call to undefined function: adodb_error() in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 17

Okay so here is my php file again

<?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 ('{$_Employee_ID}', '{$_Date}', '{$_Activity}', '{$_Miles}')" or die(ADODB_error())
      }
}


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 it keeps giving me

Parse error: parse error, unexpected '}' in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 16

 

First it was an unexpected semicolon so i deleted it, now i get this. i don't know  ??? and i don't know what to do.

 

i don't see any missing " ' s or anything  :-\

<?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 ('{$_Employee_ID}', '{$_Date}', '{$_Activity}', $_Miles}')") or die(ADODB_error());
      }
}
function error($error)
{
   //if error is equal to blank
   if($error == 'blank')
      {
      echo "Please fill in all the required fields before submitting";
      }
}   
?>

 

Notice: Undefined variable: _Employee_ID in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 15

Notice: Undefined variable: _Date in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 15

Notice: Undefined variable: _Activity in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 15

Notice: Undefined variable: _Miles in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 15

Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Syntax error in query expression '}')'. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 15

Fatal error: Call to undefined function: adodb_error() in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 15

 

 

 

:'( this is beyond frustrating now. You have no idea how much i appreciate all of your help.

don't know why I didn't see this earlier

 

$_Employee_ID}', '{$_Date}', '{$_Activity}', $_Miles.....don't exist

according to your script

 

you need to have

'{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}'

 

 

and adodb_error() doesn't exist as the last error states

just use a simple error statement

 

$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 with your ... thing");

Okay i'm dumb and forgot something...  i need to verify the employeeid before it submits. the employeeid's are stored in a table named analyzer_query.

 

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

 

is this correct?

 

if it is where should i put it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.