I am selecting names and dates from a database (Postgresql). They are displaying on the web in two tables. I'm trying to collect employee attendance at training sessions that were offered on various dates in the AM and PM. When I try to insert what is posted I get the message 'undefined index'. I'm sure it's because I haven't named the selected records on the form (dissn,dt,AM,PM,datestamp,timestamp). I don't really know the correct syntax to do this. Here is the code I have written:
include ('gen.php');
if(sizeof($_POST)==0)
{
error("Nice try; sdatt.php can only be accessed via the menu");
}
if(array_key_exists('username',$POST) && array_key_exists('password',$POST))
{
$database = pg_connect("dbname=$DB user=".$POST['username']." password=".$POST['password']."") or error("Database Connection failed; Check your username or password:");
if(array_key_exists('attendance',$_POST))
{
html_open_header("sdatt.php",$_POST['username'],$_POST['password']);
echo "<TABLE BORDER=0 WIDTH=\"50%\"><TR><TD ALIGN=left>DATES:</TD><TD>";
generate_date_list($database,0,false);
echo "</TD></TR>\n</TABLE>";
echo "<TABLE BORDER=0 WIDTH=\"50%\"><TR><TD ALIGN=left>NAME:</TD><TD>";
generate_name_list($database,0,false);
echo "</TD></TR>\n</TABLE>";
}}
echo "<TABLE BORDER=0><TR><TD>CHECK ONE or BOTH TO SHOW ATTENDANCE</TD><TD>\n";
echo "<CENTER><HR><INPUT TYPE=checkbox VALUE=\"AM\" NAME=am>";
echo "<CENTER><HR><INPUT TYPE=checkbox VALUE=\"PM\" NAME=pm>";
echo "<CENTER><HR><INPUT TYPE=submit VALUE=\"POST\" NAME=post>";
if (array_key_exists('post',$_POST))
{
$i=0;
while($HTTP_POST_VARS['dissn'][$i]>""&&$HTTP_POST_VARS['dt'][$i]>""&& $HTTP_POST_VARS['am'][$i]>""&&$HTTP_POST_VARS['pm'][$i]>"")
$result = pg_query($database, "INSERT into sdtbl1 VALUES (".$HTTP_POST_VARS['dissn'][$i].",".$HTTP_POST_VARS['dt'][$i].",".$HTTP_POST_VARS['am'][$i].",".$HTTP_POST_VARS['pm'][$i].",14,'2006-06-30','','2006','test','N');")OR error ("<BR>Queryfailed<BR>");
}
function attendance($database,$dissn,$readonly)
{
$result = pg_query($database,"SELECT last_name, first_name, dissn FROM sdallstaff;") OR error("<BR>Query failed:Retrieving employee data");
$employee = pg_fetch_array($result);
echo "<TABLE><TR><TD ALIGN=right>NAME:</TD><TD><INPUT TYPE=TEXT NAME=\"dissn\" VALUE=\"".$dissn."\" SIZE=10";
if($readonly)
echo "READONLY";
echo">";
}
?>
Thanks for any help on this...