| Gast | Parse error: unexpected $end ... on line xy Hallo zusammen
Ich habe in eurem Forum viel gestöbert, konnte aber mein Problem dennoch nicht lösen.
Ich hab ein kleines Gästebuch geschrieben und bekomme stets folgende Fehlermeldung wenn ich die Datei view.php aufrufe: Zitat: |
Parse error: parse error, unexpected $end in C:\Program Files\Apache Group\Apache2\htdocs\guestbook2k\header.php on line 221
| Die view.php Datei soll es mir ermöglichen Gästebucheinträge anzusehen.
Code von view.php: Zitat:
<?php
include "header.php"; // includes main functions for the guestbook2k
?>
<table border=0>
<?php
if (empty($offset)) { $offset = 0; }
$preserve ="";
while ($row = mysql_fetch_array($result))
{
print_entry($row,$preserve,"name","location","emai l","URL","entry date","comments");
print "<tr><td colspan=2></td></tr>\n";
}
mysql_free_result($result);
?>
</table>
<?php
nav($offset);
?>
| Und die header.php verwaltet mein Gästebuch
Code von header.php: Zitat:
<?php
include("$DOCUMENT_ROOT/functions/charset.php");
include("$DOCUMENT_ROOT/functions/basic.php");
?>
<?php
$conn = mysql_connect("localhost", "root", "Chie5pha") or
die("Could not connect to database! Please try again later");
mysql_select_db("guestbook2k", $conn) or
die("Could not select guestbook2k");
define("PAGE_LIMIT", 2); /*defines a constant named PAGE_LIMIT
with value 2, the constant is everywhere
available, without declaring it as global */
##################################################
# Function: print_entry() #
# Creator: Antoine Hauck #
# Create date: 15.09.2004 #
# Origin use: guestbook2k #
##################################################
# This prints the results of a query within #
# a table #
##################################################
function print_entry($row,$preserve="")
{
$numargs = func_num_args(); /* retrieves the number of arguments of the function
the first argument will be indicated as 0 */
for ($i = 2; $i < $numargs; $i++)
{
$field = func_get_arg($i); /* the value of each function argument can be
accessed with fung_get_arg() */
$dbfield = str_replace(" ", "_", strtolower($field)); /* makes $field lowercase and replaces spaces
with underlines */
$dbvalue = cleanup_text($row[$dbfield],$preserve); //clean up the text with the cleanup_text() from $dbfield
$name = ucwords($field); //makes the first letter of each word uppercase
print " <tr>\n";
print " <td valign=top align=right>$name:</td>\n"; //prints a table with the column names of the table
print " <td valign=top align=left>$dbvalue</td>\n"; //and the according values
print " </tr>\n\n";
}
}
##################################################
# Function: print_input_fields() #
# Creator: Antoine Hauck #
# Create date: 15.09.2004 #
# Origin use: guestbook2k #
##################################################
# This function prints input fields (e.g. name, #
# location, url etc.) from the specified table #
# columns #
##################################################
function print_input_fields()
{
$fields = func_get_args(); /* makes $field an array, each element of which
is an argument sent to the function */
while (list($index,$field) = each($fields)) /* the list structure moves through all elements
in the array and prints a text field for each */
{
print " <tr>\n";
print " <td valign=top align=right>" //The name of the field will be in one table cell,
.ucfirst($field).":</td>\n";
print "<td valign=top align=left><input type=text " //and the input box will be in an adjoining cell
."name=$field size=40 value=\""
.$GLOBALS["last_$field"]."\"></td>\n";
print " </tr>\n\n";
}
}
##################################################
# Function: create_entry() #
# Creator: Antoine Hauck #
# Create date: 15.09.2004 #
# Origin use: guestbook2k #
##################################################
# Verifies the entered information and puts it #
# into the database after succeeded verification #
##################################################
function create_entry($name,$location,$email,$url,$comments )
{
$name = cleanup_text($name);
$location = cleanup_text($location);
$email = cleanup_text($email); //cleanup_text() removes HTML tags and
$url = cleanup_text($url); //escape special characters (e.g. & and ")
$comments = cleanup_text($comments);
$errmsg = ""; /* starts with an empty error message, if a
validation test fails, an error message will be
added to $errmsg */
if (empty($name)) //Checks if a name was entered
{
$errmsg .= "[*]You didn't enter a name!\n";
}
//verifies the format of $email, it must be xyz@zyx.xy
if (empty($email) || !eregi("^[A-Za-z0-9\_.-]+@[A-Za-z0-9\_-]+.[A-Za-z0-9\_-]+.*", $email))
{
$errmsg .="[*]$email doesn't look like a valid email address\n";
}
else
{
/* If the format is OK, check to see if a user (with the same $email) has already signed the guestbook
Multiple entries are not allowed! */
$query = "select * from guestbook where email ='$email'"; /* looks after entries in the database where
email = $email */
$result = safe_query($query);
if (mysql_num_rows($result) > 0) //if a result is found with $email, you got
{ //an error
$errmsg .="$email has already signed this guestbook!\n";
}
}
//perform a very simple check on the format of the url supplied by the user (if any)
if (!empty($url) && !eregi("^http://[A-Za-z0-9\%\?\_\:\~\/\.-]+$",$url))
{
$errmsg .="[*]$url doesn't look like a valid URL. Don't forget the \"http://\"\n";
}
if (empty($errmsg)) //If no error found insert data to database
{
$query = "insert into guestbook " //mySQL query: inserts the data into the database
." (name,location,email,url,comments,remote_addr) values "
."('$name', '$location', '$email', '$url', '$comments', '$REMOTE_ADDR')"
;
safe_query($query);
print "<h2>Thanks, $name!</h2>\n";
}
else
{
print <<<EOQ
<font color=red>
[b]
<ul>
$errmsg
[/list] //if an error occurs: prints the error message
Please try again
</p>
EOQ;
}
return $errmsg;
}
##################################################
# Function: select_entries() #
# Creator: Antoine Hauck #
# Create date: 16.09.2004 #
# Origin use: guestbook2k #
##################################################
# This function calls the database entries #
##################################################
function select_entries ($offset=0)
{
if (empty($offset)) { $offset = 0; } //defines an offset of 0, if no one was given
$query = "select *, date_format(created,'%e %M, %Y %h:%i %p') " //date_format retrieves "created" in a readable way
."as entry_date from guestbook order by created " //Selects the DB entries sorted by creation date
."desc limit $offset, " . PAGE_LIMIT //PAGE_LIMIT limits the number of fields to be shown
;
$result = safe_query($query);
return $result;
}
##################################################
# Function: nav() #
# Creator: Antoine Hauck #
# Create date: 18.09.2004 #
# Origin use: guestbook2k #
##################################################
# This function creates navigational elements. #
# When appropriate, this function will insert #
# links that will enable the user to view the #
# the next set of entries, the previous entries, #
# or both. It's all determined by the £offset #
# variable and the PAGE_LIMIT constant #
##################################################
function nav ($offset=0, $this_script="")
{
global $PHP_SELF;
if (empty($this_script)) { $this_script = $PHP_SELF; }
if (empty($offset)) { $offset = 0; }
// Get the total number of entries in the guestbook,
// to know if there are more entries which must be shown
$result = safe_query("select count(*) from guestbook");
list($total_rows) = mysql_fetch_array($result);
print "
\n";
if ($offset > 0)
{
// If we're not on the first row, it will insert a link,
// that will enable the user to view the previous set of entries
print "<a href=\"$this_script?offset=".($offset-PAGE_LIMIT)
."\"><<Previous Entries</a> ";
}
if ($offset+PAGE_LIMIT < $total_rows)
{
// offset + PAGE_LIMIT gives us the maximum record number
// that we could have displayed on this page. If it's less
// than the total number of rows of entries, that means
// there are more entries to see, and we can go forward
//
// It will insert a link, that will enable the user
// to view the next set of entries
print "<a href=\"$this_script?offset=".($offset+PAGE_LIMIT)
."\">Next Entries>></a> ";
}
print "</p>\n";
}
?> DAS IST DIE VERFLIXTE LINIE 221 | In der header.php verweise ich auf die basic.php (hier sind meine Basisfunktionen fürs Gästebuch.
Code von basic.php: Zitat:
<?php
##################################################
# Function: authenticate() #
# Creator: Antoine Hauck #
# Create date: 15.09.2004 #
# Origin use: guestbook2k #
##################################################
# The authenticate function sends only a header #
# to the browser. It doesn't check the values #
# entered in the textboxes. They' re checked in #
# the guestbook2k/authenticate.php file #
##################################################
function authenticate ($realm="Secure Area"
,$errmsg="Please enter a username and password"
)
{
Header("WWW-Authenticate: Basic realm=\"$realm\"");
Header("HTTP/1.0 401 Unauthorized");
die($errmsg);
}
##################################################
# Function: cleanup_text() #
# Creator: Antoine Hauck #
# Create date: 15.09.2004 #
# Origin use: guestbook2k #
##################################################
# This function makes sure we don't insert #
# malicious text into the database #
##################################################
function cleanup_text ($value = "", $preserve="", $allowed_tags="")
{
if (empty($preserve))
{
$value = strip_tags($value, $allowed_tags); //all HTML tags will be removed, except
} //$allowed_tags
$value = htmlspecialchars($value); //changes & and " to proper HTML entities
//(e.g. & and "
return $value;
}
##################################################
# Function: safe_query() #
# Creator: Antoine Hauck #
# Create date: 15.09.2004 #
# Origin use: guestbook2k #
##################################################
# This function checks a mySQL query and gives #
# and gives you detailed information, when a #
# query fails #
##################################################
function safe_query ($query = "")
{
if (empty($query)) {return FALSE; }
$result = mysql_query($query)
or die("ack! query failed: "
."[*]errorno=".mysql_errno() //gives detailed
."[*]error=".mysql_error() //information about the error
."[*]query=".$query
);
return $result;
}
?>
| Ich weiss nicht mehr weiter, die geschweiften Klammern scheinen richtig gesetzt zu sein.
Ich wäre für jeden nützlichen Tipp sehr dankbar.
Gruss
xenos1983 |