I am getting the following error when executing the script with the below code...
Parse error: syntax error, unexpected $end on line 125

I am trying to generate a completely new .php file from information stored in the database by using this .php file.
Any Suggestions??? Thanks in advance for your help!!!

<?php
session_start();
if(!isset($_SESSION['username']) || !isset($_SESSION['sid']) ||!isset($_SESSION['ip'])) {
header("Location: login.php");
exit;
}
include("connection.php");
$usershort = $_SESSION['username'];
$result = mysql_query("SELECT groupnum FROM users WHERE username = '{$usershort}'");
while($row=mysql_fetch_array($result)) {
$group = $row['groupnum'];}

$titleofpage = $_POST['titleofpage'];

$query = "INSERT INTO group{$group}_pathway (title, content1, content2, content3) VALUES ('{$titleofpage}', 'This is some default content for content block 1', 'This is some default content for content block 2', 'This is some default content for content block 3')";

// Perform the SQL query on the database.
$result = mysql_query($query);

$result2 = mysql_query("SELECT page FROM group{$group}_pathway WHERE title = '{$titleofpage}'");
while($row2=mysql_fetch_array($result2)) {
$pagenum = $row2['page'];}


/*
** open file for writing
*/
$sql = "SELECT page FROM group{$group}_pathway WHERE title = '{$titleofpage}'";
$qry = mysql_query($sql);
$filename = "group{$group}_page{$pagenum}.php";
if(!($myFile = fopen($filename, "w")))
{
print("Error: ");
print("'$filename' could not be created\n");
exit;
}

$data = <<<EOD
<HTML><HEAD><link rel="stylesheet" type="text/css" href="group1_main.php"></HEAD>
<?php
include("connection.php");
\$usershort = \$_SESSION['username'];
\$result = mysql_query("SELECT groupnum FROM users WHERE username = '{\$usershort}'");
while(\$row=mysql_fetch_array(\$result)) {
\$group = \$row['groupnum'];}
\$titleofpage = mysql_query("SELECT title FROM group1_pathway");
\$titleofpage2 = mysql_query("SELECT title FROM group1_pathway");
\$row5=mysql_fetch_array(\$titleofpage2);
\$display_title2 = \$row5['title'];
\$pagenum = mysql_query("SELECT page FROM group1_pathway ORDER BY page");
\$content1 = mysql_query("SELECT content1 FROM group1_pathway WHERE title = '{\$display_title2}'");
\$content2 = mysql_query("SELECT content2 FROM group1_pathway WHERE title = '{\$display_title2}'");
\$content3 = mysql_query("SELECT content3 FROM group1_pathway WHERE title = '{\$display_title2}'");
?>
<BODY>
<div id="container">
<div id="header">

</div>
<div id="breadcrumbs">

</div>
<div id="content">
<p> <BR /><BR />
<?php
\$row1=mysql_fetch_array(\$content1);
\$display_content1 = \$row1['content1'];
print \$display_content1;
print "<BR><BR>";
\$row2=mysql_fetch_array(\$content2);
\$display_content2 = \$row2['content2'];
print \$display_content2;
print "<BR><BR>";
\$row3=mysql_fetch_array(\$content3);
\$display_content3 = \$row3['content3'];
print \$display_content3;
print "<BR><BR>";

?>
</p>
</div>
<div id="navbar">
<ul>
<li><a href="index.html">&nbsp; Home</a></li>
<li>
<?php
for (\$i=1; \$i<=mysql_num_rows(\$pagenum); \$i++)
{
echo '<a href="group1_page{\$i}.php">';

\$row2=mysql_fetch_array(\$titleofpage);

\$display_title = \$row2['title'];
print "&nbsp; ".\$display_title;
echo "</a></li><li>";
}
?>
</li>
</ul>
</div>
</div>

</BODY></HTML>

EOD;// End Page
//write some lines to the file
fwrite($myFile, stripslashes($data), strlen(stripslashes($data)));

//close the file
fclose($myFile);


// $result = mysql_query($query);
// If the query failed, display an error.

if(!$result) {
// The dot seperates PHP code and plain text.
echo "Your query failed. " . mysql_error();
}
else {
// Display a success message!
echo "Your content has been successfully uploaded to database!<br><br>";
}
?>

Any particular reason why you are escaping these variables in this section?

\$row1=mysql_fetch_array(\$content1);
\$display_content1 = \$row1['content1'];
print \$display_content1;
print "<BR><BR>";
\$row2=mysql_fetch_array(\$content2);
\$display_content2 = \$row2['content2'];
print \$display_content2;
print "<BR><BR>";
\$row3=mysql_fetch_array(\$content3);
\$display_content3 = \$row3['content3'];
print \$display_content3;
print "<BR><BR>";

Aside from that, the unexpected $end error comes from a missing or extra } somewhere.

This article has been dead for over six months. Start a new discussion instead.