基本上我正在用 php 和 HTML 创建一个基于事件的预订系统,代码是粗体的
<?php // editappt.php // Edit appointment calendar items //
List globals for reference global $link, $result, $time, $date,
$idx, $submit_err, $cmd, $begtime, $endtime, $subj, $notes, $idx;
// Return the variables from GET function get_vars() {
global $date, $time, $submit_err;
foreach($_GET as $key => $value)
{
$key = $value;
} } /* Return the variables from POST -- doing this AFTER processing GET variables ensures that POST variables are not altered
by the URL */ function post_vars() {
foreach($_POST as $key => $value)
{
global $key;
$key = $value;
print $value;
} } // Open connection to DB function open_db() {
$db = "calendar";
$link = mysql_connect(localhost,root,"") or die("Could not connect to server! Error: ".mysql_error());
mysql_select_db($db,$link) or die("Could not select $db! Error: ".mysql_error());
return($link); } // Get the appt for the specified date and time function get_appt($date,$time) {
global $link;
$query = "SELECT * FROM appts WHERE date = '$date ' ";
$query = $query."AND (\"$time\" >= begtime AND \"$time\" <= endtime)";
$result = mysql_query($query,$link) or die("Query Error!<p>Query: $query<p> Error: " + mysql_error());
// Return the results
return($result); } // Print the appt form for $date function print_appt($result) { print $link + $date + $time +
$submit_err + $begtime + $endtime + $subj + $notes + $idx; }
// Assemble select list "name" from first to last by step
// match = initially selected item, time = format for time function print_list($name,$first,$last,$step,$match,$time) {
print "<select name=\"$name\" size=\"1\">";
if ($tmp == $match)
{
echo " selected";
echo ">$tmp\n";
}
else
{
$tmp = $x;
}
for ($x = $first; $x <= $last; $x=$x+$step)
{
echo "\t<option";
if ($time)
{
$tmp = date("H:i",$x);
}
echo "</select>\n";
$this_script = $_SERVER['PHP_SELF'];
// If this isnt a redisplay because of error, init vars
if (!$submit_err)
{
$begtime = $time;
$endtime = $time;
$subj = "";
$notes = "";
$idx = 0;
$cmd = "write";
// Get fields for appt, if one exists
// (else use values above)
}
while ($line = mysql_fetch_array($result,MYSQL_ASSOC))
{
$begtime = substr($line[begtime],0,5);
$endtime = substr($line[endtime],0,5);
$subj = $line[subj];
$notes = $line[notes];
$idx = $line[idx];
$cmd = "update";
} } // Start form with state fields (hidden) print <<<HTML <html> <body> <form action="$this_script" method="post">
<input type="hidden" name="date" value="$date"> <input
type="hidden" name="cmd" value="$cmd"> <input type="hidden"
name="idx" value="$idx"> <table border="0" width="100%"> HTML;
echo "<tr>\n\t<td colspan=\"2\">\n"; // Display date in M D and Y
select lists print_list("month",1,12,1,substr($date,5,2),FALSE);
print_list("day",1,31,1,substr($date,8,2),FALSE); $year =
substr($date,0,4);
print_list("year",$year-1,$year+2,1,$year,FALSE); echo "<p>\n";
// Display beginning and ending time in two // select lists
$sttm = strtotime("00:00"); print_list("begtime",$sttm,($sttm +
(1800*47)),1800
,$begtime,TRUE); echo " to "; print_list("endtime",$sttm,($sttm + (1800*47)),1800
,$endtime,TRUE); echo "\n</td>\n</tr>\n<tr>\n\t<td colspan=\"2\"> "; // Print any error from last submission
if ($submit_err) {
echo "<font color=\"red\">ERROR: ";
echo "$submit_err</font>\n"; } print "\t</td>\n</tr>\n"; // Display Subject and Notes print <<<HTML </select><p> <tr>
<td width="10%">Subject:</td> <td><input type="text" name="subj"
value="$subj"
size="40" maxlength="40"></td> </tr> <tr> <td>Notes:</td> <td> <textarea cols="40" rows="5" name="notes"
wrap="virtual">$notes</textarea> </td> </tr> </table> <p> <input type="submit" name="OK" value="OK"> <input
type="submit" value="Cancel" onclick="self.close()"> </form>
</body> </html> HTML; // Decode submission and write to DB //
$cmd = whether to overwrite (rewrite) or insert (write) function
write_appt($idx,$date,$begtime,$endtime,$subj,$notes,$cmd) {
global $link; // Check to make sure beginning time doesnt run
into another appt $query = "SELECT idx,begtime,endtime,subj FROM
appts WHERE date = \"$date\" AND ". "\"".$begtime."\" >= begtime AND
\"".$begtime."\" <= endtime"; $result = mysql_query($query,$link)
or die("Query Error!<p>Query: $query<p>Error: " mysql_error());
// If overlap (conflict) found, display error while ($line =
mysql_fetch_array($result,MYSQL_ASSOC)) {
if ($line[idx] != $idx)
{
$errtext = "Conflict: ".substr($line[begtime],0,5)."-" + substr($line[endtime],0,5).":".$line[subj];
return($errtext);
} } // Check to make sure ending time doesnt run into another appt $query = "SELECT idx,begtime,endtime,subj FROM appts
WHERE date = \"$date\" AND ".
"\"".$endtime."\" >= begtime AND \"".$endtime."\" <=
endtime"; $result = mysql_query($query,$link)
or die("Query Error!<p>Query: $query<p>Error:
".mysql_error()); // If overlap (conflict) found, display error while ($line =
mysql_fetch_array($result,MYSQL_ASSOC)) {
if ($line[idx] != $idx) {
$errtext = "Conflict: ".substr($line[begtime],0,5)."-".
substr($line[endtime],0,5)." : ".$line[subj];
return($errtext);
} } // Build appropriate query if ($cmd == "update") {
$query = "UPDATE appts SET
date='$date',begtime='$begtime',endtime='$endtime',".
"subj='$subj',notes='$notes' WHERE idx = '$idx'"; } else {
$query = "INSERT INTO appts VALUES
('0','$date','$begtime','$endtime','$subj','$notes','0')"; } // Handle query $result = mysql_query($query,$link)
or die("Query Error!<p>Query: $query<p>
Error: ".mysql_error()); // Close page if no errors print <<<HTML <html> <body> <form> Appointment Saved.<p> <input
type="button" value="Close" onclick="self.close()"> </form>
</body> </html> HTML; } // Main program body $link = open_db();
// Called with POST arguments? // (From another iteration of this
script) if (!empty($_POST)) { $submit_err = ""; // Get POST
data
post_vars(); // Properly format date (leading zeros on M & D) if (strlen($month) == 1) { $month = "0".$month; } if
(strlen($day) == 1) { $day = "0".$day; } $date =
$year."-".$month."-".$day; // Proper date? if
(!checkdate($month,$day,$year)) {
$submit_err = "Invalid Date!";
print_appt($result); } // Valid start and end times? (start < end)? if (strtotime($begtime) > strtotime($endtime))
{
$submit_err = "Invalid Start Time!";
print_appt($result); } // Subject exists? if (strlen($subj) == 0) {
$submit_err = "Subject is Blank!";
print_appt($result); } // Attempt write and err on conflicting appt if (!$submit_error) {
$conflict = write_appt($idx,$date,$begtime, $endtime,$subj,$notes,$cmd);
if ($conflict)
{
$submit_err = $conflict;
print_appt($result);
} } / else { // Called with GET arguments? // (From calendar) // Get GET data and print edit form get_vars();
$result = get_appt($date,$time); print_appt($result); } //
Close DB mysql_close($link); ?>}
我在第 320 行不断收到一个语法错误,说文件意外结束,谁能告诉我如何以及在哪里修复该错误。enter code here