The code has now been updated. I changed the values for dbname, username, and password, but you get the picture. //////OLD STUFF In my main body I have a statement that checks to see if once a reservations has been made if the user selects the delete button to remove the entry from the database. I broke this down into a small perl program instead of a CGI one and ran it from the command prompt without the interace. It runs fine as long as you as you give it specific values instead of user input. I think the problems is with the display_appointments() function which instead of creating separate instances of "delete" only sees a single instance no matter how many reservations are made. Thus, when you attempt to remove an item by pressing delete you get rid of all the items currently appearing on the page. This is extremely annoying as the only time you see the rest of the appointments again is if you reserve another conference room. I thought maybe I could create a conference_delete object and just delete that specific one each time. However, I thought someone might be able to point me in a better direction. I apologize if this might seem an easy solve for most folks as I am a perl n00b. Any help would be great. Thanks!! ///OLD STUFF
use Date::Manip; use DBI(); use CGI qw(:standard); require "../common.pl"; require "../sitevariables.pl"; $cur = CGI->new(); $mode = "default"; if($cur->param("mode")) { $mode = $cur->param("mode"); } $day = $cur->param("day"); $month = $cur->param("month"); $year = $cur->param("year"); $sec = $cur->param("sec"); $min = $cur->param("min"); $hour = $cur->param("hour"); $end_min = $cur->param("end_min"); $end_hour = $cur->param("end_hour"); $end_am_pm = $cur->param("end_am_pm"); $am_pm_day = $cur->param("am_pm_day"); $laptop = $cur->param("laptop"); $conf_room = $cur->param("conf_room"); @am_or_pm = ("","AM","PM"); @end_am_or_pm = ("","AM","PM"); ("","Exec","06","11","16","31","35","47","none"); @pretty_months = ("","January","Febuary","March","April","May","June", +"July","August","September","October","November","December"); $content .= "<table width=100% border=0><tr><td width=50%><a href=\".. +/index.cgi?month=$month&year=$year\"><-- back to calendar</a></td>"; $content .= "<td width=50% align=right>&nbsp;</td></tr></table>"; if($cur->param("Delete")){ $content .= delete_appointment($day,$month,$year,$hour,$min,$conf_ +room,$conf_rooms); } $content .= print_form(); if($cur->param("conf_room")){ $content .= update_day(); } $content .= display_appointments($day,$month,$year,$hour,$min,$am_pm_d +ay,$end_hour,$end_min,$end_am_pm,$conf_room); open (TEMPLATE, "../template.html")||dienice("Content-type: text/html\ +n\nCould not find template"); while (<TEMPLATE>){ $page .= $_; } $page =~ s/<!-- ?content ?-->/$content/ig; close (TEMPLATE); print "Content-type: text/html\n\n$page"; ############ BEGIN SUBROUTINES ################################# sub print_form { my $return; my ($sec,$min,$hr,$mday,$mon,$year_localtime,$wday,$yday,$isdst) = + localtime(time()); my $current_year = $year_localtime + 1900; my $current_month = $mon + 1; my $current_sec = $sec; my $current_min = $min; my $current_hour = $hr; $return .= " <center> <form method=post> <table bgcolor=$edittitlebg cellpadding=0 cellspacing=1 border=0 width +=375><tr><td> <table bgcolor=$editborder cellpadding=4 cellspacing=0 width=100%> <tr bgcolor=$edittitlebg><td><font color=$edittitlefont>Reserve a Conf +erence Room</font></td></tr> <tr><td>Date&nbsp;&nbsp;&nbsp;&nbsp; <select name=month>"; for($index=1;$index < 13;$index++){ if($month){$current_month=$month;} if($current_month==$index){ $return .="<option value=$index selected>$pretty_months[$i +ndex]</option>\n"; }else{ $return .="<option value=$index>$pretty_months[$index]</op +tion>\n"; } } $return .= " </select> &nbsp;&nbsp;&nbsp;&nbsp; <select name=day>"; for($index=1;$index < 32;$index++){ if($day){$mday=$day; $current_day = $day;} if($index == $mday){ $return .="<option value=$index selected>$index</option>\n +"; }else{ $return .="<option value=$index>$index</option>\n"; } } $return .= " </select> &nbsp;&nbsp;&nbsp;&nbsp; <select name=year>"; if($year){$current_year = $year; } for($index=$current_year-5;$index < $current_year+5;$index++){ if($current_year==$index){ $return .="<option value=\"$index\" selected>$index</optio +n>\n"; }else{ $return .="<option value=$index>$index</option>\n"; } } $return .= " </select><br> <br> </select> Start Time&nbsp;&nbsp;&nbsp;&nbsp; <select name=hour>"; if($hour){$current_hour = $hour; } #for($index=0;$index < 24;$index++){ for($index=1;$index < 13;$index++){ if($current_hour==$index){ $return .="<option value=\"$index\" selected>$index</optio +n>\n"; }else{ $return .="<option value=$index>$index</option>\n"; } } $return .= " </select> : <select name=min>"; if($min){$current_min = $min;} for($index=0;$index < 60;$index++){ if($current_min==$index){ if($index < 10) { $return .="<option value=\"$index\" selected>0$index</ +option>\n"; }else{$return .="<option value=\"$index\" selected>$index< +/option>\n"; } }else{ if($index < 10) { $return .="<option value=$index>0$index</option>\n"; }else{ $return .="<option value=$index>$index</option>\n"; + } } } $return .= " </select>&nbsp;&nbsp;&nbsp;&nbsp;<select name=am_pm_day>"; if(am_pm_day) { for($index=1;$index < 3; $index++) { if($index == 1) { $return .="<option value=$index selected>$am_or_ +pm[1]</option>\n"; } if($index == 2) { $return .="<option value=$index selected>$am_or_ +pm[2]</option>\n"; } } } $return .= " </select> <br><br> </select>End Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <select name=endy_hour +>"; if($endy_hour){ $end_hour = $endy_hour; } #for($index=0;$index < 24;$index++){ for($index=1;$index < 13;$index++){ if($current_hour==$index){ $return .="<option value=\"$index\" selected>$index</optio +n>\n"; }else{ $return .="<option value=$index>$index</option>\n"; } } $return .= " </select> : <select name=endy_min>"; if($endy_min){ $end_min = $endy_min; } for($index=0;$index < 60;$index++){ if($current_min==$index){ if($index < 10) { $return .="<option value=\"$index\" selected>0$index</ +option>\n"; }else{$return .="<option value=\"$index\" selected>$index< +/option>\n"; } }else{ if($index < 10) { $return .="<option value=$index>0$index</option>\n"; }else{ $return .="<option value=$index>$index</option>\n"; + } } } $return .= " </select>&nbsp;&nbsp;&nbsp;&nbsp;<select name=end_am_pm>"; if(end_am_pm) { for($index=1;$index < 3; $index++) { if($index == 1) { $return .="<option value=$index selected>$end_am_or_pm[1 +]</option>\n"; } if($index == 2) { $return .="<option value=$index selected>$end_am_or_pm[2 +]</option>\n"; } } } $return .= " </select> <br><br> Conference Room </select> &nbsp;&nbsp;&nbsp;&nbsp; <select name=conf_room>"; for($index=1;$index < 9;$index++){ $return .="<option value=$index selected>$conf_rooms[$inde +x]</option>\n"; } $return .= " </select><br> <!--<input type=radio name=type value=weekly>every week<br> <input type=radio name=type value=biweekly>every week<br>--> <br>Please input the following information<br> <FORM METHOD=POST ACTION=/var/www/cgi-bin/sqlcalendar/protected/update +.cgi> <PRE> <tr><td> First Name:&nbsp;<INPUT NAME=$fname SIZE=34><br><br> Last Name:&nbsp;<INPUT NAME=$lname SIZE=34><br><br> Client:&nbsp;<INPUT NAME=$client SIZE=34><br><br> <input type=submit value=Reserve> </td></tr> </font> </PRE> </td></tr> </table> </td></tr></table> </form> </center> "; return $return; } sub display_appointments($$$){ $db = DBI->connect("DBI:mysql:database=dbname;host=localhost", mys +ql, ""); if(! $db) { print "!!Connection Failed!!<P>"; die(); } my $return; $return .= "<p><center> <table bgcolor=$edittitlebg cellpadding=0 cellspacing=1 border=0 w +idth=375> <tr><td> <table bgcolor=$editborder cellpadding=4 cellspacing=0 width=1 +00%> <tr bgcolor=$edittitlebg><td> <font color=$edittitlefont>Today's Reserved Conference Roo +ms</font> </td></tr> </table> </td></tr> </table> <table> <tr> <td> "; $newDate = "$year:$month:$day"; $query = "SELECT confName, start_time, end_time FROM Rese +rves_Conf WHERE resDate='$newDate'"; $select = $db->prepare($query); $select->errstr, "\n"; $rv = $select->execute() or die "Couldn't execute query ' +$query' \n"; $select->bind_columns(undef, \$confName,\$start_time,\$en +d_time); while($select->fetchrow_arrayref()) { if($confName eq "Exec") { $return .= "<left><form method=post><input type=sub +mit value=Delete> $confName &nbsp;&nbsp;&nbsp;&nbsp; $start_time &nbsp;&nbs +p;&nbsp;&nbsp; $end_time\n </form></left><br>"; } else { $return .= "<left><form method=post><input type=sub +mit value=Delete> $confName &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp +; $start_time &nbsp;&nbsp;&nbsp;&nbsp; $end_time\n </form></left><br>"; } } $return .= " </td> </tr> </table> </center></p>"; return $return; } sub update_day(){ my $update_hour= $cur->param("hour"); my $end_hour= $cur->param("e +ndy_hour"); my $update_min= $cur->param("min"); my $end_min= $cur->param("endy +_min"); my $update_year= $cur->param("year"); my $update_ampm = $cur->para +m("am_pm_day"); my $update_month= $cur->param("month"); my $update_endam = $cur->p +aram("end_am_pm"); my $update_day= $cur->param("day"); my $update_conf_room = $cur-> +param("conf_room"); my $update_conf_rooms = $cur->param("conf_rooms"); $db = DBI->connect("DBI:mysql:database=dbname;host=localhost", mys +ql, ""); if(! $db) { print "!!Connection Failed!!<P>"; die(); } if($conf_rooms[$update_conf_room] eq "none") { $resCurrent = 1;} else { if(($update_hour == 12) && ($am_or_pm[$update_ampm] eq 'AM')) { $update_hour = 0; } if(($end_hour == 12) && ($end_am_or_pm[$update_endam] eq 'AM')) { $end_hour = 0; } if(($update_hour != 12) && ($end_hour != 12)) { if($am_or_pm[$update_ampm] eq 'PM') { $update_hour = $update_ho +ur + 12; } if($end_am_or_pm[$update_endam] eq 'PM') { $end_hour = $end_hou +r + 12; } } if ($resCurrent == 1) { print "!! Conference Room: $conf_room, has been reserved during + this time period !! \n<P>" } else { $totime = "$update_hour:$update_min:00"; $endtime = "$end_hour:$end_min:00"; $resrvDate = sprintf("%04d-%02d-%02d", $update_year, $update_mo +nth, $update_day); $statement = qq[insert into Reserves_Conf(confID,confName,start +_time,end_time, resDate,id) values('$confID','$conf_rooms[$update_co +nf_room]', '$totime','$endtime','$resrvDate','100000')]; $insert = $db->prepare($statement) or die "Couldn't prepare the + query:", $insert->errstr, "\n"; $rv = $insert->execute or die "Order insert failed: ", $insert- +>errstr, "\n"; } } $db->disconnect(); } sub delete_appointment($$$$){ my $update_conf_rooms = $cur->param("conf_rooms"); my $update_conf +_room = $cur->param("conf_room"); my $update_hour = $cur->param("hour"); my $update_min = $cur->para +m("min"); my $update_year = $cur->param("year");my $update_month = $cur->par +am("month"); my $update_day = $cur->param("day"); $db = DBI->connect("DBI:mysql:database=dbname;host=localhost", mys +ql, ""); if(! $db) { print "!!Connection Failed!!<P>"; die(); } $query = "select confName from Reserves_Conf WHERE confName = '$up +date_conf_rooms[$update_conf_room]'"; $select = $db->prepare($query); $select->errstr, "\n"; $rv = $select->execute() or die "Couldn't execute query '$query' \ +n"; $select->bind_columns(undef, \$confName); $newDate = sprintf("%04d-%02d-%02d", $update_year, $update_month, +$update_day); $newTime = "$update_hour:$update_min:00"; $statement = "DELETE FROM Reserves_Conf WHERE resDate='$newDate' A +ND start_time='$newTime'"; $statement = $db->prepare($statement); $statement->errstr, "\n"; $rv = $statement->execute() or die "Couldn't execute query '$query +' \n"; $db->disconnect(); }

In reply to Form Submit Problems by intranetman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.